From 2de7da80b0986ef20db5b454404a331b17211a10 Mon Sep 17 00:00:00 2001 From: ReignOfComputer Date: Sun, 5 Feb 2017 23:23:02 +0800 Subject: [PATCH 1/2] Add Check for Bad Ability Length Prevents System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. --- PKHeX.WinForms/MainWindow/MainPK4.cs | 6 +++++- PKHeX.WinForms/MainWindow/MainPK5.cs | 7 +++++-- PKHeX.WinForms/MainWindow/MainPK6.cs | 9 +++++++-- PKHeX.WinForms/MainWindow/MainPK7.cs | 8 ++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/MainPK4.cs b/PKHeX.WinForms/MainWindow/MainPK4.cs index c222bf9f5..64121dc44 100644 --- a/PKHeX.WinForms/MainWindow/MainPK4.cs +++ b/PKHeX.WinForms/MainWindow/MainPK4.cs @@ -142,7 +142,11 @@ namespace PKHeX.WinForms pk4.SID = Util.ToInt32(TB_SID.Text); pk4.EXP = Util.ToUInt32(TB_EXP.Text); pk4.PID = Util.getHEXval(TB_PID.Text); - pk4.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + + if (CB_Ability.Text.Length >= 4) + { + pk4.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + } pk4.FatefulEncounter = CHK_Fateful.Checked; pk4.Gender = PKX.getGender(Label_Gender.Text); diff --git a/PKHeX.WinForms/MainWindow/MainPK5.cs b/PKHeX.WinForms/MainWindow/MainPK5.cs index 92c18e5df..a36ac2ea7 100644 --- a/PKHeX.WinForms/MainWindow/MainPK5.cs +++ b/PKHeX.WinForms/MainWindow/MainPK5.cs @@ -247,8 +247,11 @@ namespace PKHeX.WinForms } else { - pk5.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); - pk5.HiddenAbility = CB_Ability.SelectedIndex > 1; // not 0 or 1 + if (CB_Ability.Text.Length >= 4) + { + pk5.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + pk5.HiddenAbility = CB_Ability.SelectedIndex > 1; // not 0 or 1 + } } // Fix Moves if a slot is empty diff --git a/PKHeX.WinForms/MainWindow/MainPK6.cs b/PKHeX.WinForms/MainWindow/MainPK6.cs index 43a4238a5..6943d250a 100644 --- a/PKHeX.WinForms/MainWindow/MainPK6.cs +++ b/PKHeX.WinForms/MainWindow/MainPK6.cs @@ -184,8 +184,13 @@ namespace PKHeX.WinForms pk6.TID = Util.ToInt32(TB_TID.Text); pk6.SID = Util.ToInt32(TB_SID.Text); pk6.EXP = Util.ToUInt32(TB_EXP.Text); - pk6.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); - pk6.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + + if (CB_Ability.Text.Length >= 4) + { + pk6.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + pk6.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + } + // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag) pk6.PID = Util.getHEXval(TB_PID.Text); pk6.Nature = (byte)WinFormsUtil.getIndex(CB_Nature); diff --git a/PKHeX.WinForms/MainWindow/MainPK7.cs b/PKHeX.WinForms/MainWindow/MainPK7.cs index b9591eab2..56b4c727e 100644 --- a/PKHeX.WinForms/MainWindow/MainPK7.cs +++ b/PKHeX.WinForms/MainWindow/MainPK7.cs @@ -184,8 +184,12 @@ namespace PKHeX.WinForms pk7.TID = Util.ToInt32(TB_TID.Text); pk7.SID = Util.ToInt32(TB_SID.Text); pk7.EXP = Util.ToUInt32(TB_EXP.Text); - pk7.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); - pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + + { + pk7.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + } + // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag) pk7.PID = Util.getHEXval(TB_PID.Text); pk7.Nature = (byte)WinFormsUtil.getIndex(CB_Nature); From c7e570b92d489eec5d2885999fbb0ef248da1a50 Mon Sep 17 00:00:00 2001 From: ReignOfComputer Date: Sun, 5 Feb 2017 23:23:17 +0800 Subject: [PATCH 2/2] Add Check for Bad Ability Length 2 Forgot to save, again. --- PKHeX.WinForms/MainWindow/MainPK7.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PKHeX.WinForms/MainWindow/MainPK7.cs b/PKHeX.WinForms/MainWindow/MainPK7.cs index 56b4c727e..df8660054 100644 --- a/PKHeX.WinForms/MainWindow/MainPK7.cs +++ b/PKHeX.WinForms/MainWindow/MainPK7.cs @@ -185,6 +185,7 @@ namespace PKHeX.WinForms pk7.SID = Util.ToInt32(TB_SID.Text); pk7.EXP = Util.ToUInt32(TB_EXP.Text); + if (CB_Ability.Text.Length >= 4) { pk7.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number