From 127d2c2aaaf6a31f4eebe55d782d2a29256955d5 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 20 Mar 2017 00:03:31 -0700 Subject: [PATCH] static analysis fixes fixes the friend safari form checks (if else were chained incorrectly) argumentorder of some unused sections (BV date, canlearnmachinemove) --- PKHeX.WinForms/MainWindow/Main.cs | 11 ++++---- PKHeX.WinForms/MainWindow/MainPK4.cs | 4 +-- PKHeX.WinForms/MainWindow/MainPK5.cs | 2 +- .../Subforms/Save Editors/Gen6/SAV_Link6.cs | 1 + .../Save Editors/Gen7/SAV_PokedexSM.cs | 2 +- .../Save Editors/Gen7/SAV_Trainer7.cs | 4 +-- .../Subforms/Save Editors/SAV_EventFlags.cs | 3 +-- .../Subforms/Save Editors/SAV_Inventory.cs | 4 +-- PKHeX/Legality/Analysis.cs | 2 +- PKHeX/Legality/Checks.cs | 27 ++++++++++++------- PKHeX/Legality/Core.cs | 2 +- PKHeX/MysteryGifts/PGT.cs | 2 +- PKHeX/PKM/ShowdownSet.cs | 2 +- PKHeX/Saves/SAV3Colosseum.cs | 3 ++- PKHeX/Saves/Substructures/BV6.cs | 4 +-- 15 files changed, 42 insertions(+), 31 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index cd3bc4ca2..415a6678a 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -297,7 +297,8 @@ namespace PKHeX.WinForms // Select Language string l = Settings.Language; int lang = Array.IndexOf(GameInfo.lang_val, l); - if (lang < 0) Array.IndexOf(GameInfo.lang_val, "en"); + if (lang < 0) + lang = Array.IndexOf(GameInfo.lang_val, "en"); if (lang > -1) languageID = lang; @@ -2998,10 +2999,10 @@ namespace PKHeX.WinForms // Refresh Move Legality for (int i = 0; i < 4; i++) - movePB[i].Visible = !Legality.vMoves[i].Valid && !HaX; + movePB[i].Visible = !Legality.vMoves[i].Valid; for (int i = 0; i < 4; i++) - relearnPB[i].Visible = !Legality.vRelearn[i].Valid && !HaX && pkm.Format >= 6; + relearnPB[i].Visible = !Legality.vRelearn[i].Valid && pkm.Format >= 6; if (skipMoveRepop) return; @@ -3465,7 +3466,7 @@ namespace PKHeX.WinForms setParty(); getSlotColor(slot, Resources.slotSet); } - else if (slot < 30 || HaX && slot >= 36 && slot < 42) + else if (slot < 30 || HaX) { if (slot < 30) { @@ -3509,7 +3510,7 @@ namespace PKHeX.WinForms getSlotColor(slot, Resources.slotDel); return; } - if (slot < 30 || HaX && slot >= 36 && slot < 42) + if (slot < 30 || HaX) { if (slot < 30) { diff --git a/PKHeX.WinForms/MainWindow/MainPK4.cs b/PKHeX.WinForms/MainWindow/MainPK4.cs index 64121dc44..911ff341a 100644 --- a/PKHeX.WinForms/MainWindow/MainPK4.cs +++ b/PKHeX.WinForms/MainWindow/MainPK4.cs @@ -127,7 +127,7 @@ namespace PKHeX.WinForms else if (abils[0] == abils[1] || abils[1] == 0) CB_Ability.SelectedIndex = pk4.PIDAbility; else - CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil; + CB_Ability.SelectedIndex = abil >= CB_Ability.Items.Count ? 0 : abil; } } private PKM preparePK4() @@ -364,7 +364,7 @@ namespace PKHeX.WinForms else if (abils[0] == abils[1] || abils[1] == 0) CB_Ability.SelectedIndex = pk4.PIDAbility; else - CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil; + CB_Ability.SelectedIndex = abil >= CB_Ability.Items.Count ? 0 : abil; } } private PKM prepareBK4() diff --git a/PKHeX.WinForms/MainWindow/MainPK5.cs b/PKHeX.WinForms/MainWindow/MainPK5.cs index a36ac2ea7..c9edf5b66 100644 --- a/PKHeX.WinForms/MainWindow/MainPK5.cs +++ b/PKHeX.WinForms/MainWindow/MainPK5.cs @@ -140,7 +140,7 @@ namespace PKHeX.WinForms else if (abils[0] == abils[1] || abils[1] == 0) CB_Ability.SelectedIndex = pk5.PIDAbility; else - CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil; + CB_Ability.SelectedIndex = abil >= CB_Ability.Items.Count ? 0 : abil; } } private PKM preparePK5() diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs index 61aa9e619..f32f5c561 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Link6.cs @@ -23,6 +23,7 @@ namespace PKHeX.WinForms { WinFormsUtil.Alert("Invalid save file / Link Information"); Close(); + return; } data = data.Skip(0x1FF).Take(PL6.Size).ToArray(); loadLinkData(data); diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs index 5dd5d5ba8..86fa527e4 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_PokedexSM.cs @@ -236,7 +236,7 @@ namespace PKHeX.WinForms } private void setEntry() { - if (species < 0) + if (species <= 0) return; int pk = species - 1; diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index ee9adbea6..87a0e794f 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -165,8 +165,8 @@ namespace PKHeX.WinForms // Poké Finder NUD_SnapCount.Value = Math.Min(NUD_SnapCount.Maximum, SAV.PokeFinderSnapCount); - NUD_ThumbsTotal.Value = Math.Min(NUD_SnapCount.Maximum, SAV.PokeFinderThumbsTotalValue); - NUD_ThumbsRecord.Value = Math.Min(NUD_SnapCount.Maximum, SAV.PokeFinderThumbsHighValue); + NUD_ThumbsTotal.Value = Math.Min(NUD_ThumbsTotal.Maximum, SAV.PokeFinderThumbsTotalValue); + NUD_ThumbsRecord.Value = Math.Min(NUD_ThumbsRecord.Maximum, SAV.PokeFinderThumbsHighValue); CB_CameraVersion.SelectedIndex = Math.Min(CB_CameraVersion.Items.Count - 1, SAV.PokeFinderCameraVersion); CHK_Gyro.Checked = SAV.PokeFinderGyroFlag; diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs index 2c158c6ea..2d4560076 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_EventFlags.cs @@ -305,8 +305,7 @@ namespace PKHeX.WinForms if (editing) return; editing = true; - - editing = true; + Constants[CB_Stats.SelectedIndex] = (ushort)(Util.ToUInt32(((MaskedTextBox)sender).Text) & 0xFFFF); MaskedTextBox m = TLP_Flags.Controls[constTag + CB_Stats.SelectedIndex.ToString("0000")] as MaskedTextBox; if (m != null) diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs index 2a7f6af3c..1df07e5a0 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Inventory.cs @@ -122,7 +122,7 @@ namespace PKHeX.WinForms }; dgv.Columns.Add(dgvFree); } - if (HasFreeSpace) + if (HasNew) { DataGridViewCheckBoxColumn dgvNew = new DataGridViewCheckBoxColumn { @@ -243,7 +243,7 @@ namespace PKHeX.WinForms NUD_Count.Maximum = byte.MaxValue; else if (SAV.Generation >= 7) NUD_Count.Maximum = pouch.MaxCount; - else if (SAV.Generation >= 3) + else // if (SAV.Generation >= 3) NUD_Count.Maximum = ushort.MaxValue; } else diff --git a/PKHeX/Legality/Analysis.cs b/PKHeX/Legality/Analysis.cs index cf9f59b36..0a6c235b0 100644 --- a/PKHeX/Legality/Analysis.cs +++ b/PKHeX/Legality/Analysis.cs @@ -190,7 +190,7 @@ namespace PKHeX.Core EncounterType = (EncounterOriginal ?? EncounterMatch)?.GetType(); if (EncounterType == typeof (MysteryGift)) - EncounterType = EncounterType.BaseType; + EncounterType = EncounterType?.BaseType; } private void updateChecks() { diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index 8af197cdb..af2d72695 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -563,18 +563,27 @@ namespace PKHeX.Core private CheckResult verifyEncounterSafari() { - if (pkm.Species == 670 || pkm.Species == 671) // Floette - if (!new[] {0, 1, 3}.Contains(pkm.AltForm)) // 0/1/3 - RBY - return new CheckResult(Severity.Invalid, "Friend Safari: Not valid color.", CheckIdentifier.Encounter); - else if (pkm.Species == 710 || pkm.Species == 711) // Pumpkaboo - if (pkm.AltForm != 1) // Average - return new CheckResult(Severity.Invalid, "Friend Safari: Not average sized.", CheckIdentifier.Encounter); - else if (pkm.Species == 586) // Sawsbuck - if (pkm.AltForm != 0) - return new CheckResult(Severity.Invalid, "Friend Safari: Not Spring form.", CheckIdentifier.Encounter); + switch (pkm.Species) + { + case 670: // Floette + case 671: // Florges + if (!new[] {0, 1, 3}.Contains(pkm.AltForm)) // 0/1/3 - RBY + return new CheckResult(Severity.Invalid, "Friend Safari: Not valid color.", CheckIdentifier.Encounter); + break; + case 710: // Pumpkaboo + case 711: // Goregeist + if (pkm.AltForm != 1) // Average + return new CheckResult(Severity.Invalid, "Friend Safari: Not average sized.", CheckIdentifier.Encounter); + break; + case 586: // Sawsbuck + if (pkm.AltForm != 0) + return new CheckResult(Severity.Invalid, "Friend Safari: Not Spring form.", CheckIdentifier.Encounter); + break; + } return new CheckResult(Severity.Valid, "Valid Friend Safari encounter.", CheckIdentifier.Encounter); } + private CheckResult verifyEncounterWild() { EncounterSlot[] enc = (EncounterSlot[])EncounterMatch; diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 25dce34e8..4f6a11fea 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -1321,7 +1321,7 @@ namespace PKHeX.Core internal static bool getCanLearnMachineMove(PKM pkm, int move, IEnumerable generations, GameVersion version = GameVersion.Any) { - return generations.Any(generation => getCanLearnMachineMove(pkm, generation, move, version)); + return generations.Any(generation => getCanLearnMachineMove(pkm, move, generation, version)); } internal static bool getCanRelearnMove(PKM pkm, int move, IEnumerable generations, GameVersion version = GameVersion.Any) { diff --git a/PKHeX/MysteryGifts/PGT.cs b/PKHeX/MysteryGifts/PGT.cs index 19beab60b..99b783d60 100644 --- a/PKHeX/MysteryGifts/PGT.cs +++ b/PKHeX/MysteryGifts/PGT.cs @@ -255,7 +255,7 @@ namespace PKHeX.Core } // Generate Met Info - if (IsPokémon) + if (!IsEgg) { pk4.Met_Location = pk4.Egg_Location + 3000; pk4.Egg_Location = 0; diff --git a/PKHeX/PKM/ShowdownSet.cs b/PKHeX/PKM/ShowdownSet.cs index 23454ebd9..ffe6ecbed 100644 --- a/PKHeX/PKM/ShowdownSet.cs +++ b/PKHeX/PKM/ShowdownSet.cs @@ -318,7 +318,7 @@ namespace PKHeX.Core { int index = line.LastIndexOf("(", StringComparison.Ordinal); string n1, n2; - if (index != 0) // correct format + if (index > 1) // correct format { n1 = line.Substring(0, index - 1); n2 = line.Substring(index).Trim(); diff --git a/PKHeX/Saves/SAV3Colosseum.cs b/PKHeX/Saves/SAV3Colosseum.cs index 53ca3657c..bcdc8356f 100644 --- a/PKHeX/Saves/SAV3Colosseum.cs +++ b/PKHeX/Saves/SAV3Colosseum.cs @@ -4,7 +4,7 @@ using System.Security.Cryptography; namespace PKHeX.Core { - public sealed class SAV3Colosseum : SaveFile + public sealed class SAV3Colosseum : SaveFile, IDisposable { public override string BAKName => $"{FileName} [{OT} ({Version}) - {PlayTimeString}].bak"; public override string Filter => "GameCube Save File|*.gci|All Files|*.*"; @@ -145,6 +145,7 @@ namespace PKHeX.Core // Checksums private readonly SHA1 sha1 = SHA1.Create(); + public void Dispose() => sha1.Dispose(); private byte[] EncryptColosseum(byte[] input, byte[] digest) { if (input.Length != SLOT_SIZE) diff --git a/PKHeX/Saves/Substructures/BV6.cs b/PKHeX/Saves/Substructures/BV6.cs index fa1a4d332..78e63062b 100644 --- a/PKHeX/Saves/Substructures/BV6.cs +++ b/PKHeX/Saves/Substructures/BV6.cs @@ -122,7 +122,7 @@ namespace PKHeX.Core private int MatchFlags { get { return Data[0x2E57]; } set { Data[0x2E57] = (byte)value; } } public DateTime MatchStamp { - get { return new DateTime(MatchYear, MatchDay, MatchMonth, MatchHour, MatchMinute, MatchSecond); } + get { return new DateTime(MatchYear, MatchMonth, MatchDay, MatchHour, MatchMinute, MatchSecond); } set { MatchYear = value.Year; MatchDay = value.Day; MatchMonth = value.Month; MatchHour = value.Hour; MatchMinute = value.Minute; MatchSecond = value.Second; } } private int UploadYear { get { return BitConverter.ToUInt16(Data, 0x2E58); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E58); } } @@ -134,7 +134,7 @@ namespace PKHeX.Core private int UploadFlags { get { return Data[0x2E5F]; } set { Data[0x2E5F] = (byte)value; } } public DateTime UploadStamp { - get { return new DateTime(UploadYear, UploadDay, UploadMonth, UploadHour, UploadMinute, UploadSecond); } + get { return new DateTime(UploadYear, UploadMonth, UploadDay, UploadHour, UploadMinute, UploadSecond); } set { UploadYear = value.Year; UploadDay = value.Day; UploadMonth = value.Month; UploadHour = value.Hour; UploadMinute = value.Minute; UploadSecond = value.Second; } }