diff --git a/.editorconfig b/.editorconfig index f640b535c..782aa0f49 100644 --- a/.editorconfig +++ b/.editorconfig @@ -35,6 +35,23 @@ dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:sug dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggest dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggest dotnet_style_parentheses_in_other_operators = always_for_clarity:suggest +csharp_indent_labels = one_less_than_current +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_style_namespace_declarations = block_scoped:silent +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_prefer_system_threading_lock = true:suggestion +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +dotnet_diagnostic.WFO1000.severity = none [*.{cs,vb}] #### Naming styles #### @@ -43,3 +60,67 @@ dotnet_style_parentheses_in_other_operators = always_for_clarity:suggest dotnet_naming_style.begins_with_i.required_prefix = I dotnet_naming_style.begins_with_i.capitalization = pascal_case + +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +end_of_line = crlf +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_explicit_tuple_names = true:suggestion + +# IDE0130: Namespace does not match folder structure +dotnet_diagnostic.IDE0130.severity = none diff --git a/.github/README-de.md b/.github/README-de.md index bad205ab9..2dcca6124 100644 --- a/.github/README-de.md +++ b/.github/README-de.md @@ -28,9 +28,9 @@ PKHeX erwartet entschlüsselte Spielstände. Da diese konsolenspezifisch verschl ## Erstellen -PKHeX ist eine Windows Forms Anwendung, welche die [.NET 8.0](https://dotnet.microsoft.com/download/dotnet/8.0) runtime benötigt. +PKHeX ist eine Windows Forms Anwendung, welche die [.NET 9.0](https://dotnet.microsoft.com/download/dotnet/9.0) runtime benötigt. -Die Anwendung kann mit jedem Kompiler erstellt werden, der C# 12 unterstützt. +Die Anwendung kann mit jedem Kompiler erstellt werden, der C# 13 unterstützt. ### Erstell Konfiguration diff --git a/.github/README-es.md b/.github/README-es.md index 9bca5366e..9c94a13df 100644 --- a/.github/README-es.md +++ b/.github/README-es.md @@ -28,9 +28,9 @@ PKHeX espera archivos de guardado que no estén cifrados con las claves específ ## Building -PKHeX es una aplicación de Windows Forms que requiere [.NET 8.0](https://dotnet.microsoft.com/download/dotnet/8.0). +PKHeX es una aplicación de Windows Forms que requiere [.NET 9.0](https://dotnet.microsoft.com/download/dotnet/9.0). -El archivo ejecutable puede ser construido con cualquier compilador que soporte C# 12. +El archivo ejecutable puede ser construido con cualquier compilador que soporte C# 13. ### Configuraciones del Build diff --git a/.github/README-fr.md b/.github/README-fr.md index 9f5fdc4d4..28d0a0cb0 100644 --- a/.github/README-fr.md +++ b/.github/README-fr.md @@ -27,9 +27,9 @@ PKHeX attend des fichiers de sauvegarde qui ne sont pas chiffrés avec des clés ## Construction -PKHeX est une application Windows Forms qui nécessite [.NET 8.0.](https://dotnet.microsoft.com/download/dotnet/8.0) +PKHeX est une application Windows Forms qui nécessite [.NET 9.0.](https://dotnet.microsoft.com/download/dotnet/9.0) -L'exécutable peut être construit avec n'importe quel compilateur prenant en charge C# 12. +L'exécutable peut être construit avec n'importe quel compilateur prenant en charge C# 13. ### Construire les configurations diff --git a/.github/README-it.md b/.github/README-it.md index ac2ba85c0..eb5e69bde 100644 --- a/.github/README-it.md +++ b/.github/README-it.md @@ -28,9 +28,9 @@ PKHeX si aspetta file di salvataggio non criptati con le chiavi specifiche della ## Building -PKHeX è un applicazione Windows Form che necessita del [.NET Desktop Runtime 8.0](https://dotnet.microsoft.com/download/dotnet/8.0). +PKHeX è un applicazione Windows Form che necessita del [.NET Desktop Runtime 9.0](https://dotnet.microsoft.com/download/dotnet/9.0). -L'eseguibile può essere compilato con qualsiasi compiler che supporti C# 12. +L'eseguibile può essere compilato con qualsiasi compiler che supporti C# 13. ### Configurazioni di Build diff --git a/.github/README-zh-Hans.md b/.github/README-zh-Hans.md index d5cd74363..2473c0f2d 100644 --- a/.github/README-zh-Hans.md +++ b/.github/README-zh-Hans.md @@ -28,9 +28,9 @@ PKHeX 所读取存档文件必须是未经主机唯一密钥加密,因此请 ## 构建 -PKHeX 是 Windows 窗口应用程序,依赖于 [.NET 8.0](https://dotnet.microsoft.com/download/dotnet/8.0)。 +PKHeX 是 Windows 窗口应用程序,依赖于 [.NET 9.0](https://dotnet.microsoft.com/download/dotnet/9.0)。 -可以使用任何支持 C# 12 的编译器生成可执行文件。 +可以使用任何支持 C# 13 的编译器生成可执行文件。 ### 构建配置 diff --git a/.github/README-zh-Hant.md b/.github/README-zh-Hant.md index 5ce43c735..e5ca632ea 100644 --- a/.github/README-zh-Hant.md +++ b/.github/README-zh-Hant.md @@ -28,9 +28,9 @@ PKHeX 所讀取檔案須未經主機唯一密鑰加密,因而請使用儲存 ## 構建 -PKHeX 係 Windows 窗體應用程式,其須依賴於 [.NET 7.0](https://dotnet.microsoft.com/download/dotnet/8.0)。 +PKHeX 係 Windows 窗體應用程式,其須依賴於 [.NET 9.0](https://dotnet.microsoft.com/download/dotnet/9.0)。 -程式可透過任意支援 C# 12 之編譯器構建。 +程式可透過任意支援 C# 13 之編譯器構建。 ### 構建配置 diff --git a/Directory.Build.props b/Directory.Build.props index b04ad423f..66ae3be32 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ 24.11.11 - 12 + 13 enable en PKHeX diff --git a/PKHeX.Core/Editing/Saves/BoxManip/BoxManipDefaults.cs b/PKHeX.Core/Editing/Saves/BoxManip/BoxManipDefaults.cs index 8c8518715..fdbf165c7 100644 --- a/PKHeX.Core/Editing/Saves/BoxManip/BoxManipDefaults.cs +++ b/PKHeX.Core/Editing/Saves/BoxManip/BoxManipDefaults.cs @@ -12,8 +12,8 @@ public static class BoxManipDefaults /// /// Common sorting actions. /// - public static readonly IReadOnlyList SortCommon = new List - { + public static readonly IReadOnlyList SortCommon = + [ new BoxManipSort(SortSpecies, EntitySorting.OrderBySpecies), new BoxManipSort(SortSpeciesReverse, EntitySorting.OrderByDescendingSpecies), new BoxManipSort(SortLevel, EntitySorting.OrderByLevel), @@ -24,13 +24,13 @@ public static class BoxManipDefaults new BoxManipSortComplex(SortParty, (list, sav, start) => list.BubbleUp(sav, i => ((SAV7b)sav).Blocks.Storage.IsParty(i), start), s => s is SAV7b), new BoxManipSort(SortShiny, list => list.OrderByCustom(pk => !pk.IsShiny)), new BoxManipSort(SortRandom, list => list.OrderByCustom(_ => Util.Rand.Next())), - }; + ]; /// /// Advanced sorting actions. /// - public static readonly IReadOnlyList SortAdvanced = new List - { + public static readonly IReadOnlyList SortAdvanced = + [ new BoxManipSort(SortUsage, EntitySorting.OrderByUsage, s => s.Generation >= 3), new BoxManipSort(SortPotential, list => list.OrderByCustom(pk => (pk.MaxIV * 6) - pk.IVTotal)), new BoxManipSort(SortTraining, list => list.OrderByCustom(pk => (pk.MaxEV * 6) - pk.EVTotal)), @@ -45,13 +45,13 @@ public static class BoxManipDefaults new BoxManipSort(SortMarks, list => list.OrderByCustom(pk => pk is IRibbonSetMarks s ? int.MaxValue - s.MarkCount : 0), s => s.BlankPKM is IRibbonSetMarks), new BoxManipSort(SortLegal, list => list.OrderByCustom(pk => !new LegalityAnalysis(pk).Valid)), new BoxManipSort(SortEncounterType, list => list.OrderByCustom(pk => new LegalityAnalysis(pk).Info.EncounterMatch.LongName)), - }; + ]; /// /// Common deletion actions. /// - public static readonly IReadOnlyList ClearCommon = new List - { + public static readonly IReadOnlyList ClearCommon = + [ new BoxManipClear(DeleteAll, _ => true), new BoxManipClear(DeleteEggs, pk => pk.IsEgg, s => s.Generation >= 2 && s is not SAV8LA), new BoxManipClearComplex(DeletePastGen, (pk, sav) => pk.Generation != sav.Generation, s => s.Generation >= 4), @@ -61,13 +61,13 @@ public static class BoxManipDefaults new BoxManipClear(DeleteItemless, pk => pk.HeldItem == 0, s => s is not SAV8LA), new BoxManipClear(DeleteIllegal, pk => !new LegalityAnalysis(pk).Valid), new BoxManipClearDuplicate(DeleteClones, pk => SearchUtil.GetCloneDetectMethod(CloneDetectionMethod.HashDetails)(pk)), - }; + ]; /// /// Common modifying actions. /// - public static readonly IReadOnlyList ModifyCommon = new List - { + public static readonly IReadOnlyList ModifyCommon = + [ new BoxManipModifyComplex(ModifyHatchEggs, (pk, sav) => pk.ForceHatchPKM(sav), s => s.Generation >= 2 && s is not SAV8LA), new BoxManipModify(ModifyMaxFriendship, pk => pk.MaximizeFriendship()), new BoxManipModify(ModifyMaxLevel, pk => pk.MaximizeLevel()), @@ -78,5 +78,5 @@ public static class BoxManipDefaults new BoxManipModify(ModifyRemoveNicknames, pk => pk.SetDefaultNickname()), new BoxManipModify(ModifyRemoveItem, pk => pk.HeldItem = 0, s => s.Generation >= 2), new BoxManipModify(ModifyHeal, pk => pk.Heal(), s => s.Generation >= 6), // HP stored in box, or official code has bugged transfer PP the user would like to rectify. - }; + ]; } diff --git a/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWork.cs b/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWork.cs index 7eef03518..c74bc6ba3 100644 --- a/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWork.cs +++ b/PKHeX.Core/Editing/Saves/Editors/EventWork/EventWork.cs @@ -14,7 +14,7 @@ public sealed class EventWork : EventVar where T : struct /// /// Values with known behavior. They are labeled with a humanized string. /// - public readonly IList Options = new List { new() }; + public readonly List Options = [new()]; public EventWork(int index, EventVarType t, IReadOnlyList pieces) : base(index, t, pieces[1]) { diff --git a/PKHeX.Core/Game/GameStrings/GameDataSource.cs b/PKHeX.Core/Game/GameStrings/GameDataSource.cs index 134717bb4..a93914b62 100644 --- a/PKHeX.Core/Game/GameStrings/GameDataSource.cs +++ b/PKHeX.Core/Game/GameStrings/GameDataSource.cs @@ -11,30 +11,30 @@ public sealed class GameDataSource /// /// List of values to display. /// - public static readonly IReadOnlyList Regions = new List - { + public static readonly IReadOnlyList Regions = + [ new ("Japan (日本)", 0), new ("Americas (NA/SA)", 1), new ("Europe (EU/AU)", 2), new ("China (中国大陆)", 4), new ("Korea (한국)", 5), new ("Taiwan (香港/台灣)", 6), - }; + ]; /// /// List of values to display. /// private static readonly ComboItem[] LanguageList = [ - new ComboItem("JPN (日本語)", (int)LanguageID.Japanese), - new ComboItem("ENG (English)", (int)LanguageID.English), - new ComboItem("FRE (Français)", (int)LanguageID.French), - new ComboItem("ITA (Italiano)", (int)LanguageID.Italian), - new ComboItem("GER (Deutsch)", (int)LanguageID.German), - new ComboItem("ESP (Español)", (int)LanguageID.Spanish), - new ComboItem("KOR (한국어)", (int)LanguageID.Korean), - new ComboItem("CHS (简体中文)", (int)LanguageID.ChineseS), - new ComboItem("CHT (繁體中文)", (int)LanguageID.ChineseT), + new ("JPN (日本語)", (int)LanguageID.Japanese), + new ("ENG (English)", (int)LanguageID.English), + new ("FRE (Français)", (int)LanguageID.French), + new ("ITA (Italiano)", (int)LanguageID.Italian), + new ("GER (Deutsch)", (int)LanguageID.German), + new ("ESP (Español)", (int)LanguageID.Spanish), + new ("KOR (한국어)", (int)LanguageID.Korean), + new ("CHS (简体中文)", (int)LanguageID.ChineseS), + new ("CHT (繁體中文)", (int)LanguageID.ChineseT), ]; /// diff --git a/PKHeX.Core/Legality/Encounters/Data/EncounterEvent.cs b/PKHeX.Core/Legality/Encounters/Data/EncounterEvent.cs index bb4676a98..1b060bbbd 100644 --- a/PKHeX.Core/Legality/Encounters/Data/EncounterEvent.cs +++ b/PKHeX.Core/Legality/Encounters/Data/EncounterEvent.cs @@ -101,7 +101,7 @@ public static class EncounterEvent /// Reloads the locally stored event templates. /// /// External folder(s) to source individual mystery gift template files from. - public static void RefreshMGDB(params string[] paths) + public static void RefreshMGDB(params ReadOnlySpan paths) { // If no paths are provided, clear the arrays. See the bottom of this method. HashSet? g4 = null; List? lg4 = null; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible1.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible1.cs index c1ed67526..f70ecc31f 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible1.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible1.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible1(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible2.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible2.cs index b0c5bc702..2764d91cf 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible2.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible2.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible2(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version, PKM Entity) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3.cs index f7f50de81..7cde709b2 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible3(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3GC.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3GC.cs index f1260e913..b61d01c9f 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3GC.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible3GC.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible3GC(EvoCriteria[] Chain, EncounterTypeGroup Flags) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible4.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible4.cs index 58594ca08..6607efc53 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible4.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible4.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible4(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version, PKM Entity) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible5.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible5.cs index 70e2f2dad..f69102dda 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible5.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible5.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible5(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible6.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible6.cs index e0e60dd6b..9d03c0d71 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible6.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible6.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible6(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7.cs index 9c104741f..62320a41b 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible7(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GG.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GG.cs index 533f21179..ad4f4a05b 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GG.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GG.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible7GG(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GO.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GO.cs index 9d0cc65f7..036214ce0 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GO.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible7GO.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible7GO(EvoCriteria[] Chain, EncounterTypeGroup Flags) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8.cs index bd4ec63fd..1a05247de 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible8(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8GO.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8GO.cs index 6aa64ddac..96af701fb 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8GO.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8GO.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible8GO(EvoCriteria[] Chain, EncounterTypeGroup Flags) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs index 8d7984d4c..3ed406f61 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8a.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible8a(EvoCriteria[] Chain, EncounterTypeGroup Flags) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8b.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8b.cs index 5e5fd2569..ba2437ba5 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8b.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible8b.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible8b(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version, PKM Entity) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible9.cs b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible9.cs index 70a15a027..2714d2261 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible9.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Possible/EncounterPossible9.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// public record struct EncounterPossible9(EvoCriteria[] Chain, EncounterTypeGroup Flags, GameVersion Version) : IEnumerator { - public IEncounterable Current { get; private set; } + public IEncounterable Current { get; private set; } = null!; private int Index; private int SubIndex; diff --git a/PKHeX.Core/Legality/RNG/MethodFinder.cs b/PKHeX.Core/Legality/RNG/MethodFinder.cs index 7c920a8b5..2b6c09f5d 100644 --- a/PKHeX.Core/Legality/RNG/MethodFinder.cs +++ b/PKHeX.Core/Legality/RNG/MethodFinder.cs @@ -671,7 +671,7 @@ public static class MethodFinder pidiv = PIDIV.None; return false; } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static PIDIV AnalyzeGB(PKM _) { diff --git a/PKHeX.Core/Legality/Restrictions/WordFilter.cs b/PKHeX.Core/Legality/Restrictions/WordFilter.cs index f996071e6..252552760 100644 --- a/PKHeX.Core/Legality/Restrictions/WordFilter.cs +++ b/PKHeX.Core/Legality/Restrictions/WordFilter.cs @@ -1,5 +1,5 @@ using System; -using System.Collections.Generic; +using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.Text.RegularExpressions; @@ -52,7 +52,8 @@ public static class WordFilter /// /// Due to some messages repeating (Trainer names), keep a list of repeated values for faster lookup. /// - private static readonly Dictionary Lookup = new(INIT_COUNT); + private static readonly ConcurrentDictionary.AlternateLookup> Lookup = + new ConcurrentDictionary().GetAlternateLookup>(); /// /// Checks to see if a phrase contains filtered content. @@ -60,45 +61,35 @@ public static class WordFilter /// Phrase to check for /// Matching regex that filters the phrase. /// Boolean result if the message is filtered or not. - public static bool IsFiltered(string message, [NotNullWhen(true)] out string? regMatch) + public static bool IsFiltered(ReadOnlySpan message, [NotNullWhen(true)] out string? regMatch) { - if (string.IsNullOrWhiteSpace(message) || message.Length <= 1) + if (message.IsWhiteSpace() || message.Length <= 1) { regMatch = null; return false; } // Check dictionary - lock (dictLock) - { - if (Lookup.TryGetValue(message, out regMatch)) - return regMatch != null; - } + if (Lookup.TryGetValue(message, out regMatch)) + return regMatch != null; // Make the string lowercase invariant Span lowercase = stackalloc char[message.Length]; - for (int i = 0; i < lowercase.Length; i++) - lowercase[i] = char.ToLowerInvariant(message[i]); + message.ToLowerInvariant(lowercase); // not in dictionary, check patterns if (TryMatch(lowercase, out regMatch)) { - lock (dictLock) - Lookup[message] = regMatch; + Lookup.TryAdd(message, regMatch); return true; } // didn't match any pattern, cache result - lock (dictLock) - { - if ((Lookup.Count & ~MAX_COUNT) != 0) - Lookup.Clear(); // reset - Lookup[message] = regMatch = null; - } + if ((Lookup.Dictionary.Count & ~MAX_COUNT) != 0) + Lookup.Dictionary.Clear(); // reset + Lookup.TryAdd(message, regMatch = null); return false; } - private static readonly object dictLock = new(); private const int MAX_COUNT = (1 << 17) - 1; // arbitrary cap for max dictionary size - private const int INIT_COUNT = 1 << 10; // arbitrary init size to limit future doublings } diff --git a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs index e3ed66562..212f7e78b 100644 --- a/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/NicknameVerifier.cs @@ -67,7 +67,7 @@ public sealed class NicknameVerifier : Verifier // Non-nicknamed strings have already been checked. if (ParseSettings.Settings.WordFilter.IsEnabled(pk.Format) && pk.IsNicknamed) { - if (WordFilter.IsFiltered(nickname.ToString(), out var badPattern)) + if (WordFilter.IsFiltered(nickname, out var badPattern)) data.AddLine(GetInvalid($"Word Filter: {badPattern}")); if (TrainerNameVerifier.ContainsTooManyNumbers(nickname, data.Info.Generation)) data.AddLine(GetInvalid("Word Filter: Too many numbers.")); diff --git a/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs b/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs index 6b9dce11a..a4eb668ab 100644 --- a/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/TrainerNameVerifier.cs @@ -54,12 +54,14 @@ public sealed class TrainerNameVerifier : Verifier if (ParseSettings.Settings.WordFilter.IsEnabled(pk.Format)) { - if (WordFilter.IsFiltered(trainer.ToString(), out var badPattern)) + if (WordFilter.IsFiltered(trainer, out var badPattern)) data.AddLine(GetInvalid($"Word Filter: {badPattern}")); if (ContainsTooManyNumbers(trainer, data.Info.Generation)) data.AddLine(GetInvalid("Word Filter: Too many numbers.")); - if (WordFilter.IsFiltered(pk.HandlingTrainerName, out badPattern)) + Span ht = stackalloc char[pk.TrashCharCountTrainer]; + int nameLen = pk.LoadString(pk.HandlingTrainerTrash, ht); + if (WordFilter.IsFiltered(ht[..nameLen], out badPattern)) data.AddLine(GetInvalid($"Word Filter: {badPattern}")); } } diff --git a/PKHeX.Core/PKHeX.Core.csproj b/PKHeX.Core/PKHeX.Core.csproj index 0f21cdd92..f72afddf0 100644 --- a/PKHeX.Core/PKHeX.Core.csproj +++ b/PKHeX.Core/PKHeX.Core.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 Pokémon C# Class Library PKHeX.Core diff --git a/PKHeX.Core/PKM/Util/SpeciesName.cs b/PKHeX.Core/PKM/Util/SpeciesName.cs index a7f8aaee5..ca233e70d 100644 --- a/PKHeX.Core/PKM/Util/SpeciesName.cs +++ b/PKHeX.Core/PKM/Util/SpeciesName.cs @@ -157,11 +157,9 @@ public static class SpeciesName } Span result = stackalloc char[nick.Length]; - nick.CopyTo(result); // All names are uppercase. - foreach (ref var c in result) - c = char.ToUpperInvariant(c); + nick.AsSpan().ToUpperInvariant(result); if (language == (int)LanguageID.French) StringConverter4Util.StripDiacriticsFR4(result); // strips accents on E and I diff --git a/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs b/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs index 469c6ab10..d2460275a 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockMetadata.cs @@ -19,7 +19,7 @@ public sealed class SaveBlockMetadata public IEnumerable GetSortedBlockList() { - return BlockList.Select(z => z.Key).OrderBy(z => z); + return BlockList.Select(z => z.Key).Order(); } public IDataIndirect GetBlock(string name) => BlockList.First(z => z.Key == name).Value; diff --git a/PKHeX.Core/Saves/SAV2.cs b/PKHeX.Core/Saves/SAV2.cs index 6103d5a2d..3d41eab08 100644 --- a/PKHeX.Core/Saves/SAV2.cs +++ b/PKHeX.Core/Saves/SAV2.cs @@ -814,7 +814,7 @@ public sealed class SAV2 : SaveFile, ILangDeviantSave, IEventFlagArray, IEventWo } public bool IsGBMobileAvailable => Japanese && Version == GameVersion.C; - public bool IsGBMobileEnabled => Japanese && Enum.IsDefined(typeof(GBMobileCableColor), GBMobileCable); + public bool IsGBMobileEnabled => Japanese && Enum.IsDefined(GBMobileCable); public GBMobileCableColor GBMobileCable { diff --git a/PKHeX.Core/Saves/SAV2Stadium.cs b/PKHeX.Core/Saves/SAV2Stadium.cs index c71ba37d2..a0c66d5fe 100644 --- a/PKHeX.Core/Saves/SAV2Stadium.cs +++ b/PKHeX.Core/Saves/SAV2Stadium.cs @@ -70,7 +70,7 @@ public sealed class SAV2Stadium : SAV_STADIUM, IBoxDetailName ClearBoxes(); } - protected sealed override void SetChecksums() + protected override void SetChecksums() { base.SetChecksums(); SetMailChecksums(); diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/Daycare8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/Daycare8b.cs index 2d35bfb44..7cb632e87 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/Daycare8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/Daycare8b.cs @@ -14,7 +14,7 @@ public sealed class Daycare8b(SAV8BS sav, Memory raw) : SaveBlock( // BLOCK STRUCTURE // PB8[2] Parents; // bool32 eggExist; - // ulong eggSeed; -- setter puts only 32 bits! + // ulong eggSeed; -- setter does sign extension from signed 32 bit value! // int32 eggStepCount; private const int SlotCount = 2; @@ -62,9 +62,15 @@ public sealed class Daycare8b(SAV8BS sav, Memory raw) : SaveBlock( set => WriteUInt64LittleEndian(ExtraData[4..], value); } + /// + /// Sign extension when setting a 32-bit integer seed to a 64-bit value. + /// + /// If the top bit is set in the 32-bit unsigned representation, bits 32-63 will be set as well. + public void SetSeed(int seed) => Seed = (ulong)seed; + public int EggStepCount { - get => ReadInt32LittleEndian(ExtraData[8..]); - set => WriteInt32LittleEndian(ExtraData[8..], value); + get => ReadInt32LittleEndian(ExtraData[12..]); + set => WriteInt32LittleEndian(ExtraData[12..], value); } } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs index 0935c97fb..9b4888aa9 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs @@ -151,9 +151,9 @@ public sealed class FashionUnlock8(SAV8SWSH sav, SCBlock block) : SaveBlock InvalidFashionOffset_M => [ - 0x969, 0xB00, 0xC48, 0xC49, 0xC4A, 0xD57, 0xE37, 0xE38, 0xE39 + 0x969, 0xB00, 0xC48, 0xC49, 0xC4A, 0xD57, 0xE37, 0xE38, 0xE39, ]; private static ReadOnlySpan InvalidFashionOffset_F => [ - 0x95D, 0xB00, 0xD76, 0xD77, 0xE41, 0xE47 + 0x95D, 0xB00, 0xD76, 0xD77, 0xE41, 0xE47, ]; } diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs index 2810746ab..e1edc7852 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail2.cs @@ -55,7 +55,7 @@ public sealed class Mail2 : MailDetail }; #region Offsets - public static int GetMailboxOffset(int language) => 0x600 + (COUNT_PARTY * 2) * GetMailSize(language); + public static int GetMailboxOffset(int language) => 0x600 + ((COUNT_PARTY * 2) * GetMailSize(language)); private static int GetMailOffset(int index, int size) { @@ -75,7 +75,7 @@ public sealed class Mail2 : MailDetail { if ((uint)index >= COUNT_MAILBOX) throw new ArgumentOutOfRangeException(nameof(index)); - return (index * size) + (0x600 + (COUNT_PARTY * 2) * size + 1); + return (index * size) + (0x600 + ((COUNT_PARTY * 2) * size) + 1); } public static int GetMailboxOffsetStadium2(int language) => SAV2Stadium.MailboxBlockOffset(language) + 1; @@ -137,7 +137,7 @@ public sealed class Mail2 : MailDetail public override void SetMessage(string line1, string line2, bool userEntered) { - if (IsEmpty == true && line1 == string.Empty && line2 == string.Empty) + if (IsEmpty == true && line1.Length == 0 && line2.Length == 0) { Data.AsSpan(0, MESSAGE_LENGTH).Clear(); return; @@ -158,7 +158,7 @@ public sealed class Mail2 : MailDetail // Japanese/international user-entered mail always has a line break at index 0x10 var span1 = Data.AsSpan(0, LINE_LENGTH); SetString(span1, line1, LINE_LENGTH); - if (line2 != string.Empty) // Pad the first line with spaces if needed + if (line2.Length != 0) // Pad the first line with spaces if needed span1.Replace(0x50, 0x7F); Data[LINE_LENGTH] = LineBreakCode; var span2 = Data.AsSpan(LINE_LENGTH + 1, LINE_LENGTH); diff --git a/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs b/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs index b180526ca..37036b787 100644 --- a/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs +++ b/PKHeX.Core/Saves/Substructures/Mail/Mail3.cs @@ -36,7 +36,7 @@ public sealed class Mail3 : MailDetail set { var span = Data.AsSpan(0x12, 8); - if (value == string.Empty) + if (value.Length == 0) { span.Fill(0xFF); return; diff --git a/PKHeX.Core/Util/Util.cs b/PKHeX.Core/Util/Util.cs index 4d9b3df20..b1801db45 100644 --- a/PKHeX.Core/Util/Util.cs +++ b/PKHeX.Core/Util/Util.cs @@ -117,55 +117,23 @@ public static partial class Util return result; } -#if NET9_0_OR_GREATER - REPLACE WITH TryFromHexString / TryToHexString -#endif - /// - /// Parses a variable length hex string (non-spaced, bytes in reverse order). + /// Parses a variable length hex string (non-spaced, bytes in order). /// public static byte[] GetBytesFromHexString(ReadOnlySpan input) - { - byte[] result = new byte[input.Length / 2]; - GetBytesFromHexString(input, result); - return result; - } + => Convert.FromHexString(input); /// public static void GetBytesFromHexString(ReadOnlySpan input, Span result) - { - for (int i = 0; i < result.Length; i++) - { - var slice = input.Slice(i * 2, 2); - result[^(i + 1)] = (byte)GetHexValue(slice); - } - } - - private const string HexChars = "0123456789ABCDEF"; + => Convert.FromHexString(input, result, out _, out _); /// - /// Converts the byte array into a hex string (non-spaced, bytes in reverse order). + /// Converts the byte array into a hex string (non-spaced, bytes in order). /// public static string GetHexStringFromBytes(ReadOnlySpan data) { System.Diagnostics.Debug.Assert(data.Length is (4 or 8 or 12 or 16)); - Span result = stackalloc char[data.Length * 2]; - GetHexStringFromBytes(data, result); - return new string(result); - } - - /// - public static void GetHexStringFromBytes(ReadOnlySpan data, Span result) - { - if (result.Length != data.Length * 2) - throw new ArgumentException("Result buffer must be twice the size of the input buffer."); - for (int i = 0; i < data.Length; i++) - { - // Write tuples from the opposite side of the result buffer. - var offset = (data.Length - i - 1) * 2; - result[offset + 0] = HexChars[data[i] >> 4]; - result[offset + 1] = HexChars[data[i] & 0xF]; - } + return Convert.ToHexString(data); } /// diff --git a/PKHeX.Drawing.Misc/PKHeX.Drawing.Misc.csproj b/PKHeX.Drawing.Misc/PKHeX.Drawing.Misc.csproj index e2d0d547b..2e6de7087 100644 --- a/PKHeX.Drawing.Misc/PKHeX.Drawing.Misc.csproj +++ b/PKHeX.Drawing.Misc/PKHeX.Drawing.Misc.csproj @@ -1,7 +1,7 @@ - net8.0-windows + net9.0-windows PKHeX.Drawing.Misc diff --git a/PKHeX.Drawing.PokeSprite/PKHeX.Drawing.PokeSprite.csproj b/PKHeX.Drawing.PokeSprite/PKHeX.Drawing.PokeSprite.csproj index 1240f6327..6d09eb918 100644 --- a/PKHeX.Drawing.PokeSprite/PKHeX.Drawing.PokeSprite.csproj +++ b/PKHeX.Drawing.PokeSprite/PKHeX.Drawing.PokeSprite.csproj @@ -1,7 +1,7 @@ - net8.0-windows + net9.0-windows PKHeX.Drawing.PokeSprite diff --git a/PKHeX.Drawing/PKHeX.Drawing.csproj b/PKHeX.Drawing/PKHeX.Drawing.csproj index e04075958..77a522950 100644 --- a/PKHeX.Drawing/PKHeX.Drawing.csproj +++ b/PKHeX.Drawing/PKHeX.Drawing.csproj @@ -1,7 +1,7 @@ - net8.0-windows + net9.0-windows PKHeX.Drawing diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index f55c5a212..1089a8e9f 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -84,13 +84,13 @@ public sealed partial class PKMEditor : UserControl, IMainEditor FlickerInterface(); } - private sealed class ValidationRequiredSet(Control[] Controls, Func ShouldCheck, Func State) + private sealed class ValidationRequiredSet(Control[] controls, Func shouldCheck, Func isState) { public Control? IsNotValid(PKM pk) { - if (!ShouldCheck(pk)) + if (!shouldCheck(pk)) return null; - return Array.Find(Controls, z => State(z)); + return Array.Find(controls, z => isState(z)); } } @@ -392,7 +392,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor } // General Use Functions // - private void SetDetailsOT(ITrainerInfo tr) + private void SetDetailsOT(T tr) where T : ITrainerInfo { if (string.IsNullOrWhiteSpace(tr.OT)) return; @@ -423,7 +423,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor UpdateNickname(this, EventArgs.Empty); } - private void SetDetailsHT(ITrainerInfo tr) + private void SetDetailsHT(T tr) where T : ITrainerInfo { var trainer = tr.OT; if (trainer.Length == 0) @@ -998,8 +998,8 @@ public sealed partial class PKMEditor : UserControl, IMainEditor if (FieldsLoaded && sender == CB_Form) { Entity.Form = (byte)CB_Form.SelectedIndex; - uint EXP = Experience.GetEXP(Entity.CurrentLevel, Entity.PersonalInfo.EXPGrowth); - TB_EXP.Text = EXP.ToString(); + uint exp = Experience.GetEXP(Entity.CurrentLevel, Entity.PersonalInfo.EXPGrowth); + TB_EXP.Text = exp.ToString(); } UpdateStats(); @@ -1182,8 +1182,8 @@ public sealed partial class PKMEditor : UserControl, IMainEditor return; // Recalculate EXP for Given Level - uint EXP = Experience.GetEXP(Entity.CurrentLevel, Entity.PersonalInfo.EXPGrowth); - TB_EXP.Text = EXP.ToString(); + uint exp = Experience.GetEXP(Entity.CurrentLevel, Entity.PersonalInfo.EXPGrowth); + TB_EXP.Text = exp.ToString(); // Check for Gender Changes UC_Gender.Gender = Entity.GetSaneGender(); @@ -1242,11 +1242,11 @@ public sealed partial class PKMEditor : UserControl, IMainEditor private void ReloadMetLocations(GameVersion version, EntityContext context) { var metList = GameInfo.GetLocationList(version, context, egg: false); - CB_MetLocation.DataSource = new BindingSource(metList, null); + CB_MetLocation.DataSource = new BindingSource(metList, string.Empty); CB_MetLocation.DropDownWidth = GetWidth(metList, CB_MetLocation.Font); var eggList = GameInfo.GetLocationList(version, context, egg: true); - CB_EggLocation.DataSource = new BindingSource(eggList, null); + CB_EggLocation.DataSource = new BindingSource(eggList, string.Empty); CB_EggLocation.DropDownWidth = GetWidth(eggList, CB_EggLocation.Font); static int GetWidth(IReadOnlyCollection items, Font f) @@ -1800,7 +1800,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor { FieldsLoaded = false; var index = WinFormsUtil.GetIndex(c); - c.DataSource = new BindingSource(LegalMoveSource.Display.DataSource, null); + c.DataSource = new BindingSource(LegalMoveSource.Display.DataSource, string.Empty); c.SelectedValue = index; FieldsLoaded = true; } @@ -2008,7 +2008,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor { FieldsLoaded = false; - bool TranslationRequired = false; + bool isTranslationRequired = false; PopulateFilteredDataSources(sav); PopulateFields(Entity); @@ -2027,7 +2027,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor { Hidden_TC.TabPages.Insert(1, Hidden_Met); TC_Editor.TabPages.Insert(1, Tab_Met); - TranslationRequired = true; + isTranslationRequired = true; } if (Entity.Format <= 2 && Hidden_TC.TabPages.Contains(Hidden_Cosmetic)) @@ -2039,7 +2039,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor { Hidden_TC.TabPages.Insert(4, Hidden_Cosmetic); TC_Editor.TabPages.Insert(4, Tab_Cosmetic); - TranslationRequired = true; + isTranslationRequired = true; } if (!HaX && sav is SAV7b) @@ -2058,7 +2058,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor // pk2 save files do not have an Origin Game stored. Prompt the met location list to update. if (Entity.Format == 2) CheckMetLocationChange(GameVersion.C, Entity.Context); - return TranslationRequired; + return isTranslationRequired; } private void CenterSubEditors() @@ -2082,13 +2082,12 @@ public sealed partial class PKMEditor : UserControl, IMainEditor } } - // ReSharper disable once FieldCanBeMadeReadOnly.Global - public Action LoadShowdownSet; + public Action LoadShowdownSet { get; set; } - private void LoadShowdownSetDefault(IBattleTemplate Set) + private void LoadShowdownSetDefault(IBattleTemplate set) { var pk = PreparePKM(); - pk.ApplySetDetails(Set); + pk.ApplySetDetails(set); PopulateFields(pk); } @@ -2152,9 +2151,9 @@ public sealed partial class PKMEditor : UserControl, IMainEditor SetCountrySubRegion(CB_Country, "countries"); CB_3DSReg.DataSource = source.ConsoleRegions; - CB_GroundTile.DataSource = new BindingSource(source.G4GroundTiles, null); - CB_Nature.DataSource = new BindingSource(source.Natures, null); - CB_StatNature.DataSource = new BindingSource(source.Natures, null); + CB_GroundTile.DataSource = new BindingSource(source.G4GroundTiles, string.Empty); + CB_Nature.DataSource = new BindingSource(source.Natures, string.Empty); + CB_StatNature.DataSource = new BindingSource(source.Natures, string.Empty); // Sub-editors Stats.InitializeDataSources(); @@ -2166,7 +2165,7 @@ public sealed partial class PKMEditor : UserControl, IMainEditor { if (!force && exist.DataSource is BindingSource b && b.Count == update.Count) return; - exist.DataSource = new BindingSource(update, null); + exist.DataSource = new BindingSource(update, string.Empty); } private void PopulateFilteredDataSources(ITrainerInfo sav, bool force = false) diff --git a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs index d7de357d7..0733fa4e8 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/StatEditor.cs @@ -739,8 +739,8 @@ public partial class StatEditor : UserControl var tera = Util.GetCBList(types[..TeraDisplayIndex]); tera.Insert(0, new(TeraOverrideNone, TeraOverrideNoneValue)); tera.Add(new(types[TeraDisplayIndex], TeraStellarValue)); - CB_TeraTypeOriginal.DataSource = new BindingSource(tera, null); - CB_TeraTypeOverride.DataSource = new BindingSource(tera, null); + CB_TeraTypeOriginal.DataSource = new BindingSource(tera, string.Empty); + CB_TeraTypeOverride.DataSource = new BindingSource(tera, string.Empty); ChangingFields = false; } @@ -757,7 +757,7 @@ public partial class StatEditor : UserControl MainEditor.UpdateSprite(); } - private void L_TeraTypeOverride_Click(object sender, EventArgs e) => CB_TeraTypeOverride.SelectedValue = Entity.SV ? (int)TeraOverrideNoneValue : CB_TeraTypeOriginal.SelectedValue; + private void L_TeraTypeOverride_Click(object sender, EventArgs e) => CB_TeraTypeOverride.SelectedValue = Entity.SV ? (int)TeraOverrideNoneValue : CB_TeraTypeOriginal.SelectedValue!; private void ChangeTeraType(object sender, EventArgs e) { diff --git a/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs b/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs index faf25cbc9..2e4c97484 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/BitmapAnimator.cs @@ -1,6 +1,7 @@ using System; using System.Buffers; using System.Drawing; +using System.Threading; using System.Timers; using System.Windows.Forms; using PKHeX.Drawing; @@ -20,7 +21,7 @@ public sealed class BitmapAnimator : IDisposable private Image? ExtraLayer; private Image?[]? GlowCache; private Image? OriginalBackground; - private readonly object Lock = new(); + private readonly Lock Lock = new(); private PictureBox? pb; private int GlowInterval; diff --git a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs index 5dc734814..65a412ba8 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SAVEditor.cs @@ -695,8 +695,10 @@ public partial class SAVEditor : UserControl, ISlotViewer, ISaveFile } else { - form = new SAV_GroupViewer(sav, M.Env.PKMEditor, g); - form.Owner = ParentForm; + form = new SAV_GroupViewer(sav, M.Env.PKMEditor, g) + { + Owner = ParentForm, + }; } form.BringToFront(); form.Show(); @@ -1263,7 +1265,7 @@ public partial class SAVEditor : UserControl, ISlotViewer, ISaveFile var current = br.CurrentSlot; var list = br.SaveNames.Select((z, i) => new ComboItem(z, i)).ToList(); CB_SaveSlot.InitializeBinding(); - CB_SaveSlot.DataSource = new BindingSource(list, null); + CB_SaveSlot.DataSource = new BindingSource(list, string.Empty); CB_SaveSlot.SelectedValue = current; } else @@ -1418,35 +1420,42 @@ public partial class SAVEditor : UserControl, ISlotViewer, ISaveFile private async void TabMouseMove(object sender, MouseEventArgs e) { - if (!IsBoxDragActive) - return; - - if (e.Location == DragStartPoint) - return; - - // Gather data - var src = SAV.CurrentBox; - var bin = SAV.GetBoxBinary(src); - - // Create Temp File to Drag - var newFile = Path.Combine(Path.GetTempPath(), $"box_{src}.bin"); try { - using var img = new Bitmap(Box.Width, Box.Height); - Box.DrawToBitmap(img, new Rectangle(0, 0, Box.Width, Box.Height)); - using var cursor = Cursor = new Cursor(img.GetHicon()); - await File.WriteAllBytesAsync(newFile, bin).ConfigureAwait(true); - DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newFile }), DragDropEffects.Copy); + if (!IsBoxDragActive) + return; + + if (e.Location == DragStartPoint) + return; + + // Gather data + var src = SAV.CurrentBox; + var bin = SAV.GetBoxBinary(src); + + // Create Temp File to Drag + var newFile = Path.Combine(Path.GetTempPath(), $"box_{src}.bin"); + try + { + using var img = new Bitmap(Box.Width, Box.Height); + Box.DrawToBitmap(img, new Rectangle(0, 0, Box.Width, Box.Height)); + using var cursor = Cursor = new Cursor(img.GetHicon()); + await File.WriteAllBytesAsync(newFile, bin).ConfigureAwait(true); + DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newFile }), DragDropEffects.Copy); + } + // Tons of things can happen with drag & drop; don't try to handle things, just indicate failure. + catch (Exception x) + { WinFormsUtil.Error("Drag && Drop Error", x); } + finally + { + Cursor = Cursors.Default; + await Task.Delay(100).ConfigureAwait(false); + IsBoxDragActive = false; + await DeleteAsync(newFile, 20_000).ConfigureAwait(false); + } } - // Tons of things can happen with drag & drop; don't try to handle things, just indicate failure. - catch (Exception x) - { WinFormsUtil.Error("Drag && Drop Error", x); } - finally + catch { - Cursor = Cursors.Default; - await Task.Delay(100).ConfigureAwait(false); - IsBoxDragActive = false; - await DeleteAsync(newFile, 20_000).ConfigureAwait(false); + // Ignore. } } diff --git a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs index a557143e4..34b7bc954 100644 --- a/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs +++ b/PKHeX.WinForms/Controls/SAV Editor/SlotChangeManager.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; -using System.Linq; using System.Media; using System.Threading.Tasks; using System.Windows.Forms; @@ -170,12 +169,19 @@ public sealed class SlotChangeManager(SAVEditor se) : IDisposable private async void DeleteAsync(string path, int delay) { - await Task.Delay(delay).ConfigureAwait(true); - if (!File.Exists(path) || Drag.Info.CurrentPath == path) - return; + try + { + await Task.Delay(delay).ConfigureAwait(true); + if (!File.Exists(path) || Drag.Info.CurrentPath == path) + return; - try { File.Delete(path); } - catch (Exception ex) { Debug.WriteLine(ex.Message); } + try { File.Delete(path); } + catch (Exception ex) { Debug.WriteLine(ex.Message); } + } + catch + { + // Ignore. + } } private string CreateDragDropPKM(PictureBox pb, bool encrypt, out bool external) @@ -201,7 +207,8 @@ public sealed class SlotChangeManager(SAVEditor se) : IDisposable private bool TryMakeDragDropPKM(PictureBox pb, byte[] data, string newfile) { File.WriteAllBytes(newfile, data); - var img = (Bitmap)pb.Image; + if (pb.Image is not Bitmap img) + return false; Drag.SetCursor(pb.FindForm(), new Cursor(img.GetHicon())); Hover.Stop(); pb.Image = null; @@ -379,7 +386,7 @@ public sealed class SlotChangeManager(SAVEditor se) : IDisposable LastSlot.CurrentBackground?.Dispose(); } - private void UpdateBoxViewAtBoxIndexes(params int[] boxIndexes) + private void UpdateBoxViewAtBoxIndexes(params ReadOnlySpan boxIndexes) { foreach (var box in Boxes) { diff --git a/PKHeX.WinForms/Controls/Slots/PokePreview.cs b/PKHeX.WinForms/Controls/Slots/PokePreview.cs index 2eaff2a89..35eb32224 100644 --- a/PKHeX.WinForms/Controls/Slots/PokePreview.cs +++ b/PKHeX.WinForms/Controls/Slots/PokePreview.cs @@ -174,7 +174,7 @@ public partial class PokePreview : Form } break; } - sb.AppendLine(line.ToString()); + sb.Append(line).AppendLine(); } var detail = sb.ToString(); @@ -182,7 +182,7 @@ public partial class PokePreview : Form while (lines.MoveNext()) { var line = lines.Current; - sb.AppendLine(line.ToString()); + sb.Append(line).AppendLine(); } var enc = sb.ToString(); return (detail.TrimEnd(), enc.TrimEnd()); diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 8dd7f4dca..d3432f591 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -1100,7 +1100,8 @@ public partial class Main : Form var qr = QREncode.GenerateQRCode(pk); - var sprite = dragout.Image; + if (dragout.Image is not Bitmap sprite) + return; var la = new LegalityAnalysis(pk, C_SAV.SAV.Personal); if (la.Parsed && pk.Species != 0) { @@ -1214,6 +1215,7 @@ public partial class Main : Form e.Effect = DragDropEffects.Copy; } + // ReSharper disable once AsyncVoidMethod private async void Dragout_MouseDown(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) @@ -1292,17 +1294,24 @@ public partial class Main : Form private async void Main_FormClosing(object sender, FormClosingEventArgs e) { - if (C_SAV.SAV.State.Edited || PKME_Tabs.PKMIsUnsaved) + try { - var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgProgramCloseUnsaved, MsgProgramCloseConfirm); - if (prompt != DialogResult.Yes) + if (C_SAV.SAV.State.Edited || PKME_Tabs.PKMIsUnsaved) { - e.Cancel = true; - return; + var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgProgramCloseUnsaved, MsgProgramCloseConfirm); + if (prompt != DialogResult.Yes) + { + e.Cancel = true; + return; + } } - } - await PKHeXSettings.SaveSettings(ConfigPath, Settings).ConfigureAwait(false); + await PKHeXSettings.SaveSettings(ConfigPath, Settings).ConfigureAwait(false); + } + catch + { + // Ignore; program is shutting down. + } } #endregion diff --git a/PKHeX.WinForms/Misc/QR.cs b/PKHeX.WinForms/Misc/QR.cs index 45f2f0857..c22aff332 100644 --- a/PKHeX.WinForms/Misc/QR.cs +++ b/PKHeX.WinForms/Misc/QR.cs @@ -49,6 +49,8 @@ public partial class QR : Form private void ResizeWindow() { var img = PB_QR.Image; + if (img == null) + return; splitContainer1.Height = splitContainer1.Panel1.Height + img.Height; splitContainer1.Width = img.Width; } @@ -76,9 +78,11 @@ public partial class QR : Form private void PB_QR_Click(object sender, EventArgs e) { + if (PB_QR.Image is not { } img) + return; if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgQRClipboardImage)) return; - try { Clipboard.SetImage(PB_QR.Image); } + try { Clipboard.SetImage(img); } // Clipboard can be locked periodically, just notify on failure. catch { WinFormsUtil.Alert(MsgQRClipboardFail); } } diff --git a/PKHeX.WinForms/PKHeX.WinForms.csproj b/PKHeX.WinForms/PKHeX.WinForms.csproj index 55844f21d..f611a70f6 100644 --- a/PKHeX.WinForms/PKHeX.WinForms.csproj +++ b/PKHeX.WinForms/PKHeX.WinForms.csproj @@ -2,7 +2,7 @@ WinExe - net8.0-windows + net9.0-windows win-x64 true true diff --git a/PKHeX.WinForms/Program.cs b/PKHeX.WinForms/Program.cs index 6f493bc2b..0f3f13f42 100644 --- a/PKHeX.WinForms/Program.cs +++ b/PKHeX.WinForms/Program.cs @@ -32,6 +32,14 @@ internal static class Program // Run the application Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + + var args = Environment.GetCommandLineArgs(); + // if an arg is "dark", set the color mode to dark + if (args.Length > 1 && args[1] == "dark") +#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + Application.SetColorMode(SystemColorMode.Dark); +#pragma warning restore WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + var splash = new SplashScreen(); new Task(() => splash.ShowDialog()).Start(); new Task(() => EncounterEvent.RefreshMGDB(WinForms.Main.MGDatabasePath)).Start(); diff --git a/PKHeX.WinForms/Properties/PKHeXSettings.cs b/PKHeX.WinForms/Properties/PKHeXSettings.cs index 96f8c8c57..97a08a146 100644 --- a/PKHeX.WinForms/Properties/PKHeXSettings.cs +++ b/PKHeX.WinForms/Properties/PKHeXSettings.cs @@ -168,15 +168,12 @@ public sealed class StartupSettings : IStartupSettings if (!GameLanguage.IsLanguageValid(value)) { // Migrate old language codes set in earlier versions. - switch (value) + _language = value switch { - case "zh": - _language = "zh-Hans"; - break; - case "zh2": - _language = "zh-Hant"; - break; - } + "zh" => "zh-Hans", + "zh2" => "zh-Hant", + _ => _language, + }; return; } _language = value; diff --git a/PKHeX.WinForms/Subforms/BoxExporter.cs b/PKHeX.WinForms/Subforms/BoxExporter.cs index 6cc5d1cb4..7338b4413 100644 --- a/PKHeX.WinForms/Subforms/BoxExporter.cs +++ b/PKHeX.WinForms/Subforms/BoxExporter.cs @@ -10,11 +10,7 @@ public partial class BoxExporter : Form private readonly SaveFile SAV; private readonly IFileNamer[] Namers = [.. EntityFileNamer.AvailableNamers]; - private BoxExportSettings Settings - { - get => (BoxExportSettings)PG_Settings.SelectedObject; - init => PG_Settings.SelectedObject = value; - } + private readonly BoxExportSettings Settings; public BoxExporter(SaveFile sav, ExportOverride eo = ExportOverride.None) { @@ -26,7 +22,7 @@ public partial class BoxExporter : Form var settings = obj.BoxExport; if (eo != 0) settings = settings with { Scope = eo == ExportOverride.All ? BoxExportScope.All : BoxExportScope.Current }; - Settings = settings; + PG_Settings.SelectedObject = Settings = settings; int index = 0; for (var i = 0; i < Namers.Length; i++) diff --git a/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs b/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs index b06cc8e12..b3faf9853 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs @@ -224,8 +224,8 @@ public partial class MemoryAmie : Form var strings = MemStrings; CB_OTMemory.InitializeBinding(); CB_CTMemory.InitializeBinding(); - CB_OTMemory.DataSource = new BindingSource(strings.Memory, null); - CB_CTMemory.DataSource = new BindingSource(strings.Memory, null); + CB_OTMemory.DataSource = new BindingSource(strings.Memory, string.Empty); + CB_CTMemory.DataSource = new BindingSource(strings.Memory, string.Empty); // Quality Chooser AddIntensity(this, strings.Species[0].Text); // None @@ -258,7 +258,7 @@ public partial class MemoryAmie : Form var memIndex = Memories.GetMemoryArgType(memory, memoryGen); var args = MemStrings.GetArgumentStrings(memIndex, memoryGen); CB_OTVar.InitializeBinding(); - CB_OTVar.DataSource = new BindingSource(args, null); + CB_OTVar.DataSource = new BindingSource(args, string.Empty); LOTV.Text = TextArgs.GetMemoryCategory(memIndex, memoryGen); LOTV.Visible = CB_OTVar.Visible = CB_OTVar.Enabled = args.Count > 1; } @@ -269,7 +269,7 @@ public partial class MemoryAmie : Form var memIndex = Memories.GetMemoryArgType(memory, memoryGen); var argvals = MemStrings.GetArgumentStrings(memIndex, memoryGen); CB_CTVar.InitializeBinding(); - CB_CTVar.DataSource = new BindingSource(argvals, null); + CB_CTVar.DataSource = new BindingSource(argvals, string.Empty); LCTV.Text = TextArgs.GetMemoryCategory(memIndex, memoryGen); LCTV.Visible = CB_CTVar.Visible = CB_CTVar.Enabled = argvals.Count > 1; } diff --git a/PKHeX.WinForms/Subforms/PKM Editors/MoveShopEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/MoveShopEditor.cs index 144c1d62f..21def9e01 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/MoveShopEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/MoveShopEditor.cs @@ -177,7 +177,7 @@ public partial class MoveShopEditor : Form for (int i = 0; i < dgv.Rows.Count; i++) { var row = dgv.Rows[i]; - var index = int.Parse((string)row.Cells[ColumnIndex].Value) - Bias; + var index = int.Parse((string)row.Cells[ColumnIndex].Value!) - Bias; var purchased = row.Cells[ColumnPurchased]; var mastered = row.Cells[ColumnMastered]; purchased.Value = Shop.GetPurchasedRecordFlag(index); @@ -190,11 +190,11 @@ public partial class MoveShopEditor : Form for (int i = 0; i < dgv.Rows.Count; i++) { var row = dgv.Rows[i]; - var index = int.Parse((string)row.Cells[ColumnIndex].Value) - Bias; + var index = int.Parse((string)row.Cells[ColumnIndex].Value!) - Bias; var purchased = row.Cells[ColumnPurchased]; var mastered = row.Cells[ColumnMastered]; - Shop.SetPurchasedRecordFlag(index, (bool)purchased.Value); - Master.SetMasteredRecordFlag(index, (bool)mastered.Value); + Shop.SetPurchasedRecordFlag(index, (bool)purchased.Value!); + Master.SetMasteredRecordFlag(index, (bool)mastered.Value!); } } diff --git a/PKHeX.WinForms/Subforms/PKM Editors/TechRecordEditor.cs b/PKHeX.WinForms/Subforms/PKM Editors/TechRecordEditor.cs index 0c9b61b4b..aa22f8efd 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/TechRecordEditor.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/TechRecordEditor.cs @@ -93,7 +93,7 @@ public partial class TechRecordEditor : Form { var row = dgv.Rows[i]; var index = int.Parse(row.Cells[ColumnIndex].Value?.ToString() ?? ""); - Record.SetMoveRecordFlag(index, (bool)row.Cells[ColumnHasFlag].Value); + Record.SetMoveRecordFlag(index, (bool)row.Cells[ColumnHasFlag].Value!); } } @@ -137,7 +137,7 @@ public partial class TechRecordEditor : Form // Toggle the checkbox of cell 0 var cell = row.Cells[ColumnHasFlag]; - cell.Value = !(bool)cell.Value; + cell.Value = !(bool)cell.Value!; } private void PressKeyCell(object sender, KeyEventArgs e) @@ -151,7 +151,7 @@ public partial class TechRecordEditor : Form // Toggle the checkbox of cell 0 var cell = row.Cells[ColumnHasFlag]; - cell.Value = !(bool)cell.Value; + cell.Value = !(bool)cell.Value!; } private void SortColumn(object sender, DataGridViewCellMouseEventArgs e) diff --git a/PKHeX.WinForms/Subforms/PKM Editors/Text.cs b/PKHeX.WinForms/Subforms/PKM Editors/Text.cs index 40effc50f..7ada64dea 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/Text.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/Text.cs @@ -127,7 +127,7 @@ public partial class TrashEditor : Form TB_Text.TextChanged += (_, _) => UpdateString(TB_Text); CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource, null); + CB_Species.DataSource = new BindingSource(GameInfo.SpeciesDataSource, string.Empty); CB_Language.InitializeBinding(); CB_Language.DataSource = GameInfo.LanguageDataSource(generation); diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index 6c13154b2..09fd5ffa0 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -302,7 +302,7 @@ public partial class SAV_Database : Form foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 }) { cb.InitializeBinding(); - cb.DataSource = new BindingSource(moves, null); + cb.DataSource = new BindingSource(moves, string.Empty); } } @@ -594,6 +594,7 @@ public partial class SAV_Database : Form return settings; } + // ReSharper disable once AsyncVoidMethod private async void B_Search_Click(object sender, EventArgs e) { B_Search.Enabled = false; diff --git a/PKHeX.WinForms/Subforms/SAV_Encounters.cs b/PKHeX.WinForms/Subforms/SAV_Encounters.cs index a672a6cea..14000bb69 100644 --- a/PKHeX.WinForms/Subforms/SAV_Encounters.cs +++ b/PKHeX.WinForms/Subforms/SAV_Encounters.cs @@ -126,7 +126,7 @@ public partial class SAV_Encounters : Form private EncounterTypeGroup[] GetTypes() { return TypeFilters.Controls.OfType().Where(z => z.Checked).Select(z => z.Name) - .Select(z => (EncounterTypeGroup)Enum.Parse(typeof(EncounterTypeGroup), z)).ToArray(); + .Select(Enum.Parse).ToArray(); } private readonly PictureBox[] PKXBOXES; @@ -213,7 +213,7 @@ public partial class SAV_Encounters : Form foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 }) { cb.InitializeBinding(); - cb.DataSource = new BindingSource(DS_Move, null); + cb.DataSource = new BindingSource(DS_Move, string.Empty); } } @@ -386,6 +386,7 @@ public partial class SAV_Encounters : Form return settings; } + // ReSharper disable once AsyncVoidMethod private async void B_Search_Click(object sender, EventArgs e) { B_Search.Enabled = false; diff --git a/PKHeX.WinForms/Subforms/SAV_FolderList.cs b/PKHeX.WinForms/Subforms/SAV_FolderList.cs index 9de02bda8..31428b2a5 100644 --- a/PKHeX.WinForms/Subforms/SAV_FolderList.cs +++ b/PKHeX.WinForms/Subforms/SAV_FolderList.cs @@ -368,7 +368,7 @@ public partial class SAV_FolderList : Form { if (dg.RowCount == 0) return; - var cm = (CurrencyManager?)BindingContext?[dg.DataSource]; + var cm = (CurrencyManager?)BindingContext?[dg.DataSource!]; cm?.SuspendBinding(); int column = CB_FilterColumn.SelectedIndex - 1; var text = TB_FilterTextContains.Text.AsSpan(); diff --git a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs index c383f795a..71d83c029 100644 --- a/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs +++ b/PKHeX.WinForms/Subforms/SAV_MysteryGiftDB.cs @@ -214,7 +214,7 @@ public partial class SAV_MysteryGiftDB : Form foreach (var cb in arr) { cb.InitializeBinding(); - cb.DataSource = new BindingSource(moves, null); + cb.DataSource = new BindingSource(moves, string.Empty); } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs index 70f8cbe5b..cd143a9b3 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Misc3.cs @@ -27,7 +27,7 @@ public partial class SAV_Misc3 : Form ReadDecorations(h); CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.ToList(), null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.ToList(), string.Empty); LoadPaintings(); } else @@ -64,7 +64,7 @@ public partial class SAV_Misc3 : Form { cba[i].Items.Clear(); cba[i].InitializeBinding(); - cba[i].DataSource = new BindingSource(legal, null); + cba[i].DataSource = new BindingSource(legal, string.Empty); var g3Species = SAV.GetWork(0x43 + i); var species = SpeciesConverter.GetNational3(g3Species); cba[i].SelectedValue = (int)species; @@ -604,7 +604,7 @@ public partial class SAV_Misc3 : Form int ctr = 0; for (int i = 0; i < data.Length; i++) { - var deco = (Decoration3)(int)dgv.Rows[i].Cells[0].Value; + var deco = (Decoration3)(int)dgv.Rows[i].Cells[0].Value!; if (deco == Decoration3.NONE) // Compression of Empty Slots continue; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs index 40b5aab73..76a1ec298 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen3/SAV_Roamer3.cs @@ -17,7 +17,7 @@ public partial class SAV_Roamer3 : Form SAV = sav; CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species, null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species, string.Empty); LoadData(); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Geonet4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Geonet4.cs index c20328c58..4623df8c6 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Geonet4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Geonet4.cs @@ -76,9 +76,9 @@ public partial class SAV_Geonet4 : Form for (int i = 0; i < DGV_Geonet.Rows.Count; i++) { var row = DGV_Geonet.Rows[i]; - var country = (int)row.Cells[0].Value; - var subregion = (int)row.Cells[2].Value; - var point = (GeonetPoint)row.Cells[4].Value; + var country = (int)row.Cells[0].Value!; + var subregion = (int)row.Cells[2].Value!; + var point = (GeonetPoint)row.Cells[4].Value!; if (country > 0) Geonet.SetCountrySubregion((byte)country, (byte)subregion, point); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs index 5e1664ca4..a2f7de0e8 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Misc4.cs @@ -30,7 +30,7 @@ public partial class SAV_Misc4 : Form accessories = GameInfo.Strings.accessories; backdrops = GameInfo.Strings.backdrops; poketchapps = GameInfo.Strings.poketchapps; - backdropsSorted = [.. backdrops.OrderBy(z => z)]; // sorted copy + backdropsSorted = [.. backdrops.Order()]; // sorted copy StatNUDA = [NUD_Stat0, NUD_Stat1, NUD_Stat2, NUD_Stat3]; StatLabelA = [L_Stat0, L_Stat1, L_Stat2, L_Stat3]; // Current, Trade, Record, Trade @@ -360,7 +360,7 @@ public partial class SAV_Misc4 : Form CB_Species.InitializeBinding(); var speciesList = GameInfo.FilteredSources.Species.Skip(1).ToList(); - CB_Species.DataSource = new BindingSource(speciesList, null); + CB_Species.DataSource = new BindingSource(speciesList, string.Empty); editing = false; CB_Stats1.SelectedIndex = 0; @@ -887,7 +887,7 @@ public partial class SAV_Misc4 : Form DisplayIndex = 0, Width = 190, FlatStyle = FlatStyle.Flat, - DataSource = new BindingSource(backdropsSorted, null), + DataSource = new BindingSource(backdropsSorted, string.Empty), }; DGV_Backdrops.Columns.Add(dgv); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs index b4d0c8072..8516bb98a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Pokedex4.cs @@ -27,7 +27,7 @@ public partial class SAV_Pokedex4 : Form // Fill List CB_Species.InitializeBinding(); var filtered = GameInfo.FilteredSources; - CB_Species.DataSource = new BindingSource(filtered.Species.Skip(1).ToList(), null); + CB_Species.DataSource = new BindingSource(filtered.Species.Skip(1).ToList(), string.Empty); for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) LB_Species.Items.Add($"{i:000} - {GameInfo.Strings.specieslist[i]}"); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Underground.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Underground.cs index ea1d11f07..014652886 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Underground.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen4/SAV_Underground.cs @@ -42,28 +42,28 @@ public partial class SAV_Underground : Form // Goods DGV_UGGoods.Rows.Add(SAV4Sinnoh.UG_POUCH_SIZE); - Item_Goods.DataSource = new BindingSource(ugGoodsSorted, null); + Item_Goods.DataSource = new BindingSource(ugGoodsSorted, string.Empty); Item_Goods.DisplayIndex = 0; DGV_UGGoods.CancelEdit(); // Spheres DGV_UGSpheres.Rows.Add(MAX_SIZE); - Item_Spheres.DataSource = new BindingSource(ugSpheres, null); + Item_Spheres.DataSource = new BindingSource(ugSpheres, string.Empty); Item_Spheres.DisplayIndex = 0; DGV_UGSpheres.CancelEdit(); // Traps DGV_UGTraps.Rows.Add(MAX_SIZE); - Item_Traps.DataSource = new BindingSource(ugTrapsSorted, null); + Item_Traps.DataSource = new BindingSource(ugTrapsSorted, string.Empty); Item_Traps.DisplayIndex = 0; DGV_UGTraps.CancelEdit(); // Treasures DGV_UGTreasures.Rows.Add(MAX_SIZE); - Item_Treasures.DataSource = new BindingSource(ugTreasuresSorted, null); + Item_Treasures.DataSource = new BindingSource(ugTreasuresSorted, string.Empty); Item_Treasures.DisplayIndex = 0; DGV_UGTreasures.CancelEdit(); } @@ -139,7 +139,7 @@ public partial class SAV_Underground : Form int ctr = 0; for (int i = 0; i < DGV_UGGoods.Rows.Count; i++) { - var str = DGV_UGGoods.Rows[i].Cells[0].Value.ToString(); + var str = DGV_UGGoods.Rows[i].Cells[0].Value!.ToString(); var itemindex = Array.IndexOf(ugGoods, str); if (itemindex <= 0) @@ -154,7 +154,7 @@ public partial class SAV_Underground : Form for (int i = 0; i < DGV_UGSpheres.Rows.Count; i++) { var row = DGV_UGSpheres.Rows[i]; - var str = row.Cells[0].Value.ToString(); + var str = row.Cells[0].Value!.ToString(); var itemindex = Array.IndexOf(ugSpheres, str); bool success = int.TryParse(row.Cells[1].Value?.ToString(), out var itemcnt); @@ -170,7 +170,7 @@ public partial class SAV_Underground : Form ctr = 0; for (int i = 0; i < DGV_UGTraps.Rows.Count; i++) { - var str = DGV_UGTraps.Rows[i].Cells[0].Value.ToString(); + var str = DGV_UGTraps.Rows[i].Cells[0].Value!.ToString(); var itemindex = Array.IndexOf(ugTraps, str); if (itemindex <= 0) @@ -184,7 +184,7 @@ public partial class SAV_Underground : Form ctr = 0; for (int i = 0; i < DGV_UGTreasures.Rows.Count; i++) { - var str = DGV_UGTreasures.Rows[i].Cells[0].Value.ToString(); + var str = DGV_UGTreasures.Rows[i].Cells[0].Value!.ToString(); var itemindex = Array.IndexOf(ugTreasures, str); if (itemindex <= 0) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_DLC5.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_DLC5.cs index 7b8095a65..87a206fe6 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_DLC5.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_DLC5.cs @@ -248,13 +248,15 @@ public partial class SAV_DLC5 : Form private void B_ExportPNGCGear_Click(object sender, EventArgs e) { + if (PB_CGearBackground.Image is not { } img) + return; using var sfd = new SaveFileDialog(); sfd.Filter = "PNG File|*.png"; sfd.FileName = "Background.png"; if (sfd.ShowDialog() != DialogResult.OK) return; - PB_CGearBackground.Image.Save(sfd.FileName, ImageFormat.Png); + img.Save(sfd.FileName, ImageFormat.Png); } private void B_ImportCGB_Click(object sender, EventArgs e) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs index 5fce35336..e0dca91b5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Misc5.cs @@ -144,7 +144,7 @@ public partial class SAV_Misc5 : Form states.Add(new ComboItem($"Unknown (0x{c:X2})", c)); cbr[i].Items.Clear(); cbr[i].InitializeBinding(); - cbr[i].DataSource = new BindingSource(states.Where(v => v.Value >= 2 || v.Value == c).ToList(), null); + cbr[i].DataSource = new BindingSource(states.Where(v => v.Value >= 2 || v.Value == c).ToList(), string.Empty); cbr[i].SelectedValue = (int)c; } @@ -160,7 +160,7 @@ public partial class SAV_Misc5 : Form states.Add(new ComboItem($"Unknown (0x{current:X2})", current)); CB_RoamStatus.Items.Clear(); CB_RoamStatus.InitializeBinding(); - CB_RoamStatus.DataSource = new BindingSource(states, null); + CB_RoamStatus.DataSource = new BindingSource(states, string.Empty); CB_RoamStatus.SelectedValue = (int)current; } @@ -307,7 +307,7 @@ public partial class SAV_Misc5 : Form { cb.Items.Clear(); cb.InitializeBinding(); - cb.DataSource = new BindingSource(PassPowerB, null); + cb.DataSource = new BindingSource(PassPowerB, string.Empty); } CB_PassPower1.SelectedValue = (int)pass.PassPower1; @@ -512,9 +512,9 @@ public partial class SAV_Misc5 : Form CB_Gender.InitializeBinding(); var filtered = GameInfo.FilteredSources; - CB_Species.DataSource = new BindingSource(filtered.Species, null); - CB_Move.DataSource = new BindingSource(filtered.Moves, null); - CB_Areas.DataSource = new BindingSource(areas, null); + CB_Species.DataSource = new BindingSource(filtered.Species, string.Empty); + CB_Move.DataSource = new BindingSource(filtered.Moves, string.Empty); + CB_Areas.DataSource = new BindingSource(areas, string.Empty); CB_Areas.SelectedIndex = 0; } @@ -608,7 +608,7 @@ public partial class SAV_Misc5 : Form private void SetGenders(EntreeSlot slot) { - CB_Gender.DataSource = new BindingSource(GetGenderChoices(slot.Species), null); + CB_Gender.DataSource = new BindingSource(GetGenderChoices(slot.Species), string.Empty); } private void B_RandForest_Click(object sender, EventArgs e) @@ -660,7 +660,7 @@ public partial class SAV_Misc5 : Form L_Form.Visible = CB_Form.Enabled = CB_Form.Visible = hasForms; var list = FormConverter.GetFormList(slot.Species, GameInfo.Strings.types, GameInfo.Strings.forms, Main.GenderSymbols, SAV.Context); - CB_Form.DataSource = new BindingSource(list, null); + CB_Form.DataSource = new BindingSource(list, string.Empty); } private void ReadSubway() diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Pokedex5.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Pokedex5.cs index 81128eb58..bfdf75cc2 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Pokedex5.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_Pokedex5.cs @@ -26,7 +26,7 @@ public partial class SAV_Pokedex5 : Form // Fill List CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), string.Empty); for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) LB_Species.Items.Add($"{i:000} - {GameInfo.Strings.Species[i]}"); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_UnityTower.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_UnityTower.cs index 6aec5e103..0882e5e80 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_UnityTower.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/SAV_UnityTower.cs @@ -94,17 +94,17 @@ public partial class SAV_UnityTower : Form for (int i = 0; i < DGV_Geonet.Rows.Count; i++) { var row = DGV_Geonet.Rows[i]; - var country = (int)row.Cells[0].Value; - var subregion = (int)row.Cells[2].Value; - var point = (GeonetPoint)row.Cells[4].Value; + var country = (int)row.Cells[0].Value!; + var subregion = (int)row.Cells[2].Value!; + var point = (GeonetPoint)row.Cells[4].Value!; if (country > 0) UnityTower.SetCountrySubregion((byte)country, (byte)subregion, point); } for (int i = 0; i < DGV_UnityTower.Rows.Count; i++) { var row = DGV_UnityTower.Rows[i]; - var unlocked = (bool)row.Cells[0].Value; - var country = (int)row.Cells[1].Value; + var unlocked = (bool)row.Cells[0].Value!; + var country = (int)row.Cells[1].Value!; UnityTower.SetUnityTowerFloor((byte)country, unlocked); } UnityTower.SetSAVCountry(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs index b4fdb4831..9fb94ede0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_HallOfFame.cs @@ -42,7 +42,7 @@ public partial class SAV_HallOfFame : Form var filtered = GameInfo.FilteredSources; CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(filtered.Species, null); + CB_Species.DataSource = new BindingSource(filtered.Species, string.Empty); CB_Move1.InitializeBinding(); CB_Move2.InitializeBinding(); @@ -50,13 +50,13 @@ public partial class SAV_HallOfFame : Form CB_Move4.InitializeBinding(); var MoveList = filtered.Moves; - CB_Move1.DataSource = new BindingSource(MoveList, null); - CB_Move2.DataSource = new BindingSource(MoveList, null); - CB_Move3.DataSource = new BindingSource(MoveList, null); - CB_Move4.DataSource = new BindingSource(MoveList, null); + CB_Move1.DataSource = new BindingSource(MoveList, string.Empty); + CB_Move2.DataSource = new BindingSource(MoveList, string.Empty); + CB_Move3.DataSource = new BindingSource(MoveList, string.Empty); + CB_Move4.DataSource = new BindingSource(MoveList, string.Empty); CB_HeldItem.InitializeBinding(); - CB_HeldItem.DataSource = new BindingSource(filtered.Items, null); + CB_HeldItem.DataSource = new BindingSource(filtered.Items, string.Empty); } private void B_Cancel_Click(object sender, EventArgs e) => Close(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs index 92d862e48..39ab807d9 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs @@ -22,7 +22,7 @@ public partial class SAV_Link6 : Form foreach (var cb in (ComboBox[])[CB_Item1, CB_Item2, CB_Item3, CB_Item4, CB_Item5, CB_Item6]) { cb.InitializeBinding(); - cb.DataSource = new BindingSource(filtered.Items, null); + cb.DataSource = new BindingSource(filtered.Items, string.Empty); } Gifts = SAV.Link.Gifts; LoadLinkData(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs index de8a400ec..1229a551c 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexORAS.cs @@ -27,7 +27,7 @@ public partial class SAV_PokedexORAS : Form // Fill List CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), string.Empty); for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) LB_Species.Items.Add($"{i:000} - {GameInfo.Strings.specieslist[i]}"); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexXY.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexXY.cs index 5067a67c4..0df8fdf46 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexXY.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_PokedexXY.cs @@ -27,7 +27,7 @@ public partial class SAV_PokedexXY : Form // Fill List CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), string.Empty); for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) LB_Species.Items.Add($"{i:000} - {GameInfo.Strings.specieslist[i]}"); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs index 6231c30ce..b09d79ee7 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs @@ -73,7 +73,9 @@ public partial class SAV_Pokepuff : Form { if (e.ColumnIndex != 1) return; - ((ComboBox)((DataGridView)sender).EditingControl).DroppedDown = true; + if (sender is not DataGridView { EditingControl: ComboBox cb }) + return; + cb.DroppedDown = true; } private void B_Cancel_Click(object sender, EventArgs e) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs index 153092c6f..5e6350d41 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SecretBase.cs @@ -48,10 +48,10 @@ public partial class SAV_SecretBase : Form CB_Form.InitializeBinding(); var filtered = GameInfo.FilteredSources; - CB_Ball.DataSource = new BindingSource(filtered.Balls, null); - CB_HeldItem.DataSource = new BindingSource(filtered.Items, null); - CB_Species.DataSource = new BindingSource(filtered.Species, null); - CB_Nature.DataSource = new BindingSource(filtered.Natures, null); + CB_Ball.DataSource = new BindingSource(filtered.Balls, string.Empty); + CB_HeldItem.DataSource = new BindingSource(filtered.Items, string.Empty); + CB_Species.DataSource = new BindingSource(filtered.Species, string.Empty); + CB_Nature.DataSource = new BindingSource(filtered.Natures, string.Empty); CB_Move1.InitializeBinding(); CB_Move2.InitializeBinding(); @@ -59,10 +59,10 @@ public partial class SAV_SecretBase : Form CB_Move4.InitializeBinding(); var moves = filtered.Moves; - CB_Move1.DataSource = new BindingSource(moves, null); - CB_Move2.DataSource = new BindingSource(moves, null); - CB_Move3.DataSource = new BindingSource(moves, null); - CB_Move4.DataSource = new BindingSource(moves, null); + CB_Move1.DataSource = new BindingSource(moves, string.Empty); + CB_Move2.DataSource = new BindingSource(moves, string.Empty); + CB_Move3.DataSource = new BindingSource(moves, string.Empty); + CB_Move4.DataSource = new BindingSource(moves, string.Empty); } private void ReloadSecretBaseList() @@ -321,7 +321,7 @@ public partial class SAV_SecretBase : Form { var abilities = PersonalTable.AO.GetFormEntry(species, form); var list = GameInfo.FilteredSources.GetAbilityList(abilities); - CB_Ability.DataSource = new BindingSource(list, null); + CB_Ability.DataSource = new BindingSource(list, string.Empty); CB_Ability.SelectedIndex = abilityIndex < 3 ? abilityIndex : 0; } @@ -332,7 +332,7 @@ public partial class SAV_SecretBase : Form CB_Form.Enabled = CB_Form.Visible = hasForms; var list = FormConverter.GetFormList(species, GameInfo.Strings.types, GameInfo.Strings.forms, Main.GenderSymbols, SAV.Context); - CB_Form.DataSource = new BindingSource(list, null); + CB_Form.DataSource = new BindingSource(list, string.Empty); } private void UpdateSpecies(object sender, EventArgs e) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs index eacc5dbad..d88abc5f5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_SuperTrain.cs @@ -35,10 +35,10 @@ public partial class SAV_SuperTrain : Form dataGridView1.Columns.Clear(); { CB_Species1.InitializeBinding(); - CB_Species1.DataSource = new BindingSource(GameInfo.FilteredSources.Species, null); + CB_Species1.DataSource = new BindingSource(GameInfo.FilteredSources.Species, string.Empty); CB_Species2.InitializeBinding(); - CB_Species2.DataSource = new BindingSource(GameInfo.FilteredSources.Species, null); + CB_Species2.DataSource = new BindingSource(GameInfo.FilteredSources.Species, string.Empty); } listBox1.SelectedIndex = 0; FillTrainingBags(); @@ -86,8 +86,9 @@ public partial class SAV_SuperTrain : Form { if (e.ColumnIndex != 1) return; - ComboBox comboBox = (ComboBox)dataGridView1.EditingControl; - comboBox.DroppedDown = true; + if (sender is not DataGridView { EditingControl: ComboBox cb }) + return; + cb.DroppedDown = true; } catch { System.Diagnostics.Debug.WriteLine("Failed to modify item."); } } @@ -120,7 +121,7 @@ public partial class SAV_SuperTrain : Form int emptyslots = 0; for (int i = 0; i < 12; i++) { - var bag = dataGridView1.Rows[i].Cells[1].Value.ToString(); + var bag = dataGridView1.Rows[i].Cells[1].Value!.ToString(); if (Array.IndexOf(trba, bag) == 0) { emptyslots++; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs index 6a3afe742..fce3845e2 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs @@ -255,7 +255,7 @@ public partial class SAV_Trainer : Form if (SAV is SAV6XY xy) { var xystat = (MyStatus6XY)xy.Status; - xystat.Fashion = (TrainerFashion6)PG_CurrentAppearance.SelectedObject; + xystat.Fashion = (TrainerFashion6)PG_CurrentAppearance.SelectedObject!; xystat.Nickname = TB_TRNick.Text; } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Capture7GG.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Capture7GG.cs index 316a96401..d42dcaf89 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Capture7GG.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Capture7GG.cs @@ -31,7 +31,7 @@ public partial class SAV_Capture7GG : Form // Fill List var species = GameInfo.FilteredSources.Species.Where(z => IsLegalSpecies(z.Value)).ToList(); CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(species, null); + CB_Species.DataSource = new BindingSource(species, string.Empty); foreach (var (text, value) in species.OrderBy(z => z.Value)) LB_Species.Items.Add($"{value:000}: {text}"); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_HallOfFame7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_HallOfFame7.cs index 7342dc694..061d47813 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_HallOfFame7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_HallOfFame7.cs @@ -27,7 +27,7 @@ public partial class SAV_HallOfFame7 : Form var cb = entries[i]; cb.Items.Clear(); cb.InitializeBinding(); - cb.DataSource = new BindingSource(specList, null); + cb.DataSource = new BindingSource(specList, string.Empty); cb.SelectedValue = (int)block.GetEntry(i); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs index 44b770a80..4ed615149 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexGG.cs @@ -27,7 +27,7 @@ public partial class SAV_PokedexGG : Form // Fill List CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), string.Empty); Dex = SAV.Blocks.Zukan; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs index e2f35992b..af9b02066 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs @@ -28,7 +28,7 @@ public partial class SAV_PokedexSM : Form // Fill List CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), string.Empty); var Species = GameInfo.Strings.Species; var names = Dex.GetEntryNames(Species); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs index 10df28a6b..24eb0456f 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7GG.cs @@ -60,7 +60,7 @@ public partial class SAV_Trainer7GG : Form CB_Language.InitializeBinding(); CB_Language.DataSource = GameInfo.LanguageDataSource(SAV.Generation); CB_Game.InitializeBinding(); - CB_Game.DataSource = new BindingSource(GameInfo.VersionDataSource.Where(z => GameVersion.Gen7b.Contains(z.Value)).ToList(), null); + CB_Game.DataSource = new BindingSource(GameInfo.VersionDataSource.Where(z => GameVersion.Gen7b.Contains(z.Value)).ToList(), string.Empty); } private void LoadTrainerInfo() diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs index 45aff7d55..da82e123a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_ZygardeCell.cs @@ -45,7 +45,7 @@ public partial class SAV_ZygardeCell : Form var ew = SAV.EventWork; for (int i = 0; i < dgv.RowCount; i++) { - string str = (string)dgv.Rows[i].Cells[2].Value; + string str = (string)dgv.Rows[i].Cells[2].Value!; int val = Array.IndexOf(states, str); if (val < 0) throw new IndexOutOfRangeException("Unable to find cell index."); @@ -73,7 +73,7 @@ public partial class SAV_ZygardeCell : Form for (int i = 0; i < dgv.RowCount; i++) { var state = dgv.Rows[i].Cells[2]; - if (Array.IndexOf(states, (string)state.Value) != 2) // Not Collected + if (Array.IndexOf(states, (string)state.Value!) != 2) // Not Collected added++; state.Value = states[2]; } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Poffin8b.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Poffin8b.cs index 243e08cdb..72a34959f 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Poffin8b.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Poffin8b.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Windows.Forms; using PKHeX.Core; @@ -186,14 +186,14 @@ public partial class SAV_Poffin8b : Form item.MstID = SetPoffinName(cells[1].Value?.ToString() ?? ""); item.Level = Parse(cells[2]); item.Taste = Parse(cells[3]); - item.IsNew = (bool)cells[4].Value; + item.IsNew = (bool)cells[4].Value!; item.FlavorSpicy = Parse(cells[5]); item.FlavorDry = Parse(cells[6]); item.FlavorSweet = Parse(cells[7]); item.FlavorBitter = Parse(cells[8]); item.FlavorSour = Parse(cells[9]); - static byte Parse(DataGridViewCell c) => (byte)(byte.TryParse(c.Value.ToString(), out var p) ? p : 0); + static byte Parse(DataGridViewCell c) => (byte)(byte.TryParse(c.Value!.ToString(), out var p) ? p : 0); } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexBDSP.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexBDSP.cs index 0c781f155..fa410d6fa 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexBDSP.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexBDSP.cs @@ -26,7 +26,7 @@ public partial class SAV_PokedexBDSP : Form // Fill List CB_Species.InitializeBinding(); - CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), null); + CB_Species.DataSource = new BindingSource(GameInfo.FilteredSources.Species.Skip(1).ToList(), string.Empty); for (int i = 1; i < SAV.MaxSpeciesID + 1; i++) LB_Species.Items.Add($"{i:000} - {GameInfo.Strings.specieslist[i]}"); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexLA.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexLA.cs index 75265f3d3..b11224c65 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexLA.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexLA.cs @@ -92,11 +92,11 @@ public partial class SAV_PokedexLA : Form // Fill List CB_Species.InitializeBinding(); var species = GameInfo.FilteredSources.Species.Where(z => PokedexSave8a.GetDexIndex(PokedexType8a.Hisui, (ushort)z.Value) != 0).ToArray(); - CB_Species.DataSource = new BindingSource(species, null); + CB_Species.DataSource = new BindingSource(species, string.Empty); CB_DisplayForm.InitializeBinding(); DisplayedForms = [new(GameInfo.Strings.types[0], 0)]; - CB_DisplayForm.DataSource = new BindingSource(DisplayedForms, null); + CB_DisplayForm.DataSource = new BindingSource(DisplayedForms, string.Empty); for (var d = 1; d < DexToSpecies.Length; d++) LB_Species.Items.Add($"{d:000} - {speciesNames[DexToSpecies[d]]}"); @@ -157,7 +157,7 @@ public partial class SAV_PokedexLA : Form DisplayedForms.Clear(); DisplayedForms.Add(new ComboItem(GameInfo.Strings.types[0], 0)); - CB_DisplayForm.DataSource = new BindingSource(DisplayedForms, null); + CB_DisplayForm.DataSource = new BindingSource(DisplayedForms, string.Empty); lastForm = 0; @@ -188,7 +188,7 @@ public partial class SAV_PokedexLA : Form DisplayedForms.Add(new ComboItem(ds[form], form)); } - CB_DisplayForm.DataSource = new BindingSource(DisplayedForms, null); + CB_DisplayForm.DataSource = new BindingSource(DisplayedForms, string.Empty); LB_Forms.DataSource = sanitized; LB_Forms.SelectedIndex = 0; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexSWSH.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexSWSH.cs index 8af538923..627541baa 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexSWSH.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_PokedexSWSH.cs @@ -47,7 +47,7 @@ public partial class SAV_PokedexSWSH : Form // Fill List CB_Species.InitializeBinding(); var species = GameInfo.FilteredSources.Species.Where(z => Dex.DexLookup.ContainsKey((ushort)z.Value)).ToArray(); - CB_Species.DataSource = new BindingSource(species, null); + CB_Species.DataSource = new BindingSource(species, string.Empty); var names = Indexes.Select(z => z.GetEntryName(speciesNames) + (Dex.DexLookup[z.Species].DexType == z.Entry.DexType ? string.Empty : "***")); foreach (var n in names) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_SealStickers8b.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_SealStickers8b.cs index 43154fe86..ff5a9e52c 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_SealStickers8b.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_SealStickers8b.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Windows.Forms; using System.Linq; @@ -109,9 +109,9 @@ public partial class SAV_SealStickers8b : Form var index = int.Parse(cells[0].Value?.ToString() ?? "0"); var item = items[index]; - item.Count = int.TryParse(cells[2].Value.ToString(), out var count) ? count : 0; - item.TotalCount = int.TryParse(cells[3].Value.ToString(), out var total) ? total : 0; - item.IsGet = (bool)cells[4].Value; + item.Count = int.TryParse(cells[2].Value!.ToString(), out var count) ? count : 0; + item.TotalCount = int.TryParse(cells[3].Value!.ToString(), out var total) ? total : 0; + item.IsGet = (bool)cells[4].Value!; } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Underground8b.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Underground8b.cs index ba0bf8daa..daf28bf53 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Underground8b.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_Underground8b.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Windows.Forms; using System.Linq; @@ -120,9 +120,9 @@ public partial class SAV_Underground8b : Form var index = int.Parse(cells[0].Value?.ToString() ?? "0"); var item = items[index]; - item.Count = int.TryParse(cells[3].Value.ToString(), out var count) ? count : 0; - item.HideNewFlag = !(bool)cells[4].Value; - item.IsFavoriteFlag = (bool)cells[5].Value; + item.Count = int.TryParse(cells[3].Value!.ToString(), out var count) ? count : 0; + item.HideNewFlag = !(bool)cells[4].Value!; + item.IsFavoriteFlag = (bool)cells[5].Value!; } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs index 53864e2d0..969634fbb 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSV.cs @@ -32,7 +32,7 @@ public partial class SAV_PokedexSV : Form const int maxSpecies = (int)Species.IronLeaves; // 1010 -- no DLC species CB_Species.InitializeBinding(); var species = GameInfo.SpeciesDataSource.Where(z => SAV.Personal.IsSpeciesInGame((ushort)z.Value) && z.Value <= maxSpecies).ToArray(); - CB_Species.DataSource = new BindingSource(species, null); + CB_Species.DataSource = new BindingSource(species, string.Empty); var list = species .Select(z => new DexMap(z)) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSVKitakami.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSVKitakami.cs index 2c193ad46..92a13780c 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSVKitakami.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_PokedexSVKitakami.cs @@ -38,7 +38,7 @@ public partial class SAV_PokedexSVKitakami : Form // Fill List CB_Species.InitializeBinding(); var species = GameInfo.SpeciesDataSource.Where(z => SAV.Personal.IsSpeciesInGame((ushort)z.Value)).ToArray(); - CB_Species.DataSource = new BindingSource(species, null); + CB_Species.DataSource = new BindingSource(species, string.Empty); var list = species .Select(z => new DexMap(z)) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Trainer9.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Trainer9.cs index a5106693f..d42f7c523 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Trainer9.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen9/SAV_Trainer9.cs @@ -409,9 +409,9 @@ public partial class SAV_Trainer9 : Form System.Media.SystemSounds.Asterisk.Play(); } - private void P_CurrPhoto_Click(object sender, EventArgs e) => IMG_Save(P_CurrPhoto.Image, "current_photo"); - private void P_CurrIcon_Click(object sender, EventArgs e) => IMG_Save(P_CurrIcon.Image, "current_icon"); - private void P_InitialIcon_Click(object sender, EventArgs e) => IMG_Save(P_InitialIcon.Image, "initial_icon"); + private void P_CurrPhoto_Click(object sender, EventArgs e) => IMG_Save(P_CurrPhoto.Image!, "current_photo"); + private void P_CurrIcon_Click(object sender, EventArgs e) => IMG_Save(P_CurrIcon.Image!, "current_icon"); + private void P_InitialIcon_Click(object sender, EventArgs e) => IMG_Save(P_InitialIcon.Image!, "initial_icon"); private void B_UnlockClothing_Click(object sender, EventArgs e) { diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs index 95f28132b..133bf2ed6 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs @@ -119,7 +119,7 @@ public sealed partial class SAV_EventFlags : Form if (e.ColumnIndex != 0 || e.RowIndex == -1) return; - bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value; + bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value!; var index = labels[e.RowIndex].Index; values[index] = chk; if (NUD_Flag.Value == index) @@ -139,7 +139,7 @@ public sealed partial class SAV_EventFlags : Form if (e.ColumnIndex != 1) return; - bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value; + bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value!; dgv.Rows[e.RowIndex].Cells[0].Value = !chk; var index = labels[e.RowIndex].Index; values[index] = !chk; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags2.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags2.cs index e40b6e06a..8d28d825c 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags2.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags2.cs @@ -119,7 +119,7 @@ public sealed partial class SAV_EventFlags2 : Form if (e.ColumnIndex != 0 || e.RowIndex == -1) return; - bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value; + bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value!; var index = labels[e.RowIndex].Index; values[index] = chk; if (NUD_Flag.Value == index) @@ -139,7 +139,7 @@ public sealed partial class SAV_EventFlags2 : Form if (e.ColumnIndex != 1) return; - bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value; + bool chk = (bool)dgv.Rows[e.RowIndex].Cells[0].Value!; dgv.Rows[e.RowIndex].Cells[0].Value = !chk; var index = labels[e.RowIndex].Index; values[index] = !chk; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs index 504e51d0a..a8a5663be 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventWork.cs @@ -134,7 +134,7 @@ public sealed partial class SAV_EventWork : Form DropDownWidth = Width + 100, }; cb.InitializeBinding(); - cb.DataSource = new BindingSource(f.Options.Select(z => new ComboItem(z.Text, z.Value)).ToList(), null); + cb.DataSource = new BindingSource(f.Options.Select(z => new ComboItem(z.Text, z.Value)).ToList(), string.Empty); cb.SelectedValue = f.Value; if (cb.SelectedIndex < 0) cb.SelectedIndex = 0; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_GameSelect.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_GameSelect.cs index 37cebf41b..6d1ddfda7 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_GameSelect.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_GameSelect.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; @@ -16,7 +16,7 @@ public partial class SAV_GameSelect : Form WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); L_Prompt.Text = string.Join(Environment.NewLine + Environment.NewLine, lines); CB_Game.InitializeBinding(); - CB_Game.DataSource = new BindingSource(items.ToList(), null); + CB_Game.DataSource = new BindingSource(items.ToList(), string.Empty); CB_Game.SelectedIndex = 0; CB_Game.Focus(); } diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs index c81879158..1c0bf24bc 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs @@ -228,7 +228,7 @@ public partial class SAV_Inventory : Form for (int i = 0; i < dgv.Rows.Count; i++) { var cells = dgv.Rows[i].Cells; - var str = cells[ColumnItem].Value.ToString(); + var str = cells[ColumnItem].Value!.ToString(); var itemindex = Array.IndexOf(itemlist, str); if (itemindex <= 0 && !HasNew) // Compression of Empty Slots @@ -243,13 +243,13 @@ public partial class SAV_Inventory : Form // create clean item data when saving var item = pouch.GetEmpty(itemindex, itemcnt); if (item is IItemFreeSpace f) - f.IsFreeSpace = (bool)cells[ColumnFreeSpace].Value; + f.IsFreeSpace = (bool)cells[ColumnFreeSpace].Value!; if (item is IItemFreeSpaceIndex fi) fi.FreeSpaceIndex = uint.TryParse(cells[ColumnFreeSpaceIndex].Value?.ToString(), out var fsi) ? fsi : 0; if (item is IItemFavorite v) - v.IsFavorite = (bool)cells[ColumnFavorite].Value; + v.IsFavorite = (bool)cells[ColumnFavorite].Value!; if (item is IItemNewFlag n) - n.IsNew = (bool)cells[ColumnNEW].Value; + n.IsNew = (bool)cells[ColumnNEW].Value!; pouch.Items[ctr] = item; ctr++; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs index bf4c03cf3..4fc73d5c5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_MailBox.cs @@ -132,7 +132,7 @@ public partial class SAV_MailBox : Form { CB_AppearPKM1.Items.Clear(); CB_AppearPKM1.InitializeBinding(); - CB_AppearPKM1.DataSource = new BindingSource(GameInfo.FilteredSources.Species.ToList(), null); + CB_AppearPKM1.DataSource = new BindingSource(GameInfo.FilteredSources.Species.ToList(), string.Empty); B_PartyUp.Visible = B_PartyDown.Visible = B_BoxUp.Visible = B_BoxDown.Visible = true; } else if (Generation is 4 or 5) @@ -142,19 +142,19 @@ public partial class SAV_MailBox : Form { a.Items.Clear(); a.InitializeBinding(); - a.DataSource = new BindingSource(species, null); + a.DataSource = new BindingSource(species, string.Empty); } var vers = GameInfo.VersionDataSource .Where(z => ((GameVersion)z.Value).GetGeneration() == Generation); CB_AuthorVersion.Items.Clear(); CB_AuthorVersion.InitializeBinding(); - CB_AuthorVersion.DataSource = new BindingSource(vers, null); + CB_AuthorVersion.DataSource = new BindingSource(vers, string.Empty); } CB_AuthorLang.Items.Clear(); CB_AuthorLang.InitializeBinding(); - CB_AuthorLang.DataSource = new BindingSource(GameInfo.LanguageDataSource(SAV.Generation), null); + CB_AuthorLang.DataSource = new BindingSource(GameInfo.LanguageDataSource(SAV.Generation), string.Empty); var ItemList = GameInfo.Strings.GetItemStrings(SAV.Context, SAV.Version); CB_MailType.Items.Clear(); diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index c44eb2770..5d2ef1aff 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -435,7 +435,7 @@ public partial class SAV_Wondercard : Form string desc = $"({mg.Type}) {string.Join(Environment.NewLine, mg.GetDescription())}"; - using var form = new QR(qr, PB_Preview.Image, desc + Environment.NewLine + "PKHeX Wonder Card @ ProjectPokemon.org"); + using var form = new QR(qr, PB_Preview.Image!, desc + Environment.NewLine + "PKHeX Wonder Card @ ProjectPokemon.org"); form.ShowDialog(); } @@ -468,6 +468,7 @@ public partial class SAV_Wondercard : Form ViewGiftData(gift); } + // ReSharper disable once AsyncVoidMethod private async void BoxSlot_MouseDown(object? sender, MouseEventArgs e) { if (sender == null) diff --git a/PKHeX.WinForms/Subforms/SettingsEditor.cs b/PKHeX.WinForms/Subforms/SettingsEditor.cs index 3e39757a0..b49d4af45 100644 --- a/PKHeX.WinForms/Subforms/SettingsEditor.cs +++ b/PKHeX.WinForms/Subforms/SettingsEditor.cs @@ -47,7 +47,7 @@ public partial class SettingsEditor : Form { var type = obj.GetType(); var props = ReflectUtil.GetPropertiesCanWritePublicDeclared(type) - .OrderBy(z => z); + .Order(); foreach (var p in props) { var state = ReflectUtil.GetValue(obj, p); diff --git a/PKHeX.WinForms/Util/WinFormsUtil.cs b/PKHeX.WinForms/Util/WinFormsUtil.cs index c52412232..4abdd0740 100644 --- a/PKHeX.WinForms/Util/WinFormsUtil.cs +++ b/PKHeX.WinForms/Util/WinFormsUtil.cs @@ -463,7 +463,7 @@ public static class WinFormsUtil "zh" => name switch { "zh-Hant" or "zh-HK" or "zh-MO" or "zh-TW" => "zh-Hant", // Traditional Chinese (Hong Kong/Macau/Taiwan) - "zh-Hans" or "zh-CN" or "zh-SG" or "zh" or _ => "zh-Hans", // Simplified Chinese (China/Singapore) + _ => "zh-Hans", // Simplified Chinese (China/Singapore) }, // Use this language code if we support it, otherwise default to English diff --git a/README.md b/README.md index 85beb4f0b..4cd9ff14d 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,9 @@ PKHeX expects save files that are not encrypted with console-specific keys. Use ## Building -PKHeX is a Windows Forms application which requires [.NET 8.0](https://dotnet.microsoft.com/download/dotnet/8.0). +PKHeX is a Windows Forms application which requires [.NET 9.0](https://dotnet.microsoft.com/download/dotnet/9.0). -The executable can be built with any compiler that supports C# 12. +The executable can be built with any compiler that supports C# 13. ### Build Configurations diff --git a/Tests/PKHeX.Core.Tests/General/GeneralTests.cs b/Tests/PKHeX.Core.Tests/General/GeneralTests.cs index fcee8dcd1..df3fa73a6 100644 --- a/Tests/PKHeX.Core.Tests/General/GeneralTests.cs +++ b/Tests/PKHeX.Core.Tests/General/GeneralTests.cs @@ -1,5 +1,6 @@ using FluentAssertions; using Xunit; +#pragma warning disable RCS1257 namespace PKHeX.Core.Tests.General; diff --git a/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs b/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs index 6b594c23c..2b1fdaa30 100644 --- a/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs +++ b/Tests/PKHeX.Core.Tests/Legality/BreedTests.cs @@ -46,7 +46,7 @@ public class BreedTests var x = origins; if (gen != 2) - x.SequenceEqual(x.OrderBy(z => z)).Should().BeTrue(); + x.SequenceEqual(x.Order()).Should().BeTrue(); else x.SequenceEqual(x.OrderBy(z => z != (byte)EggSource2.Base)).Should().BeTrue(); } diff --git a/Tests/PKHeX.Core.Tests/PKHeX.Core.Tests.csproj b/Tests/PKHeX.Core.Tests/PKHeX.Core.Tests.csproj index 239fd4512..c1033c15f 100644 --- a/Tests/PKHeX.Core.Tests/PKHeX.Core.Tests.csproj +++ b/Tests/PKHeX.Core.Tests/PKHeX.Core.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 false diff --git a/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs b/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs index 771f0647f..c1371f5aa 100644 --- a/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs +++ b/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs @@ -42,7 +42,7 @@ public class ConvertUtilTests public void CheckConvertHexString(string v, uint result) { var convert = Core.Util.GetBytesFromHexString(v); - var u32 = ReadUInt32LittleEndian(convert); + var u32 = ReadUInt32BigEndian(convert); u32.Should().Be(result); var remake = Core.Util.GetHexStringFromBytes(convert); diff --git a/Tests/PKHeX.Core.Tests/Util/TestUtil.cs b/Tests/PKHeX.Core.Tests/Util/TestUtil.cs index 5e585ba3e..887514a42 100644 --- a/Tests/PKHeX.Core.Tests/Util/TestUtil.cs +++ b/Tests/PKHeX.Core.Tests/Util/TestUtil.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Threading; namespace PKHeX.Core.Tests; @@ -17,7 +18,7 @@ internal static class TestUtil return folder; } - private static readonly object InitLock = new(); + private static readonly Lock InitLock = new(); private static bool IsInitialized; public static void InitializeLegality()