From 5cb232d474ea299392e2bdcca2cbe73b1d675eb9 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 6 May 2018 18:40:51 -0700 Subject: [PATCH] Sanity check some showdownset import values --- PKHeX.Core/PKM/Editing/CommonEdits.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/PKM/Editing/CommonEdits.cs b/PKHeX.Core/PKM/Editing/CommonEdits.cs index ae52e3a0f..7a2393bb7 100644 --- a/PKHeX.Core/PKM/Editing/CommonEdits.cs +++ b/PKHeX.Core/PKM/Editing/CommonEdits.cs @@ -172,6 +172,8 @@ public static void SetMaximumPPUps(this PKM pk, int[] Moves = null) /// Option to maximize PP Ups public static void SetMoves(this PKM pk, int[] Moves, bool maxPP = false) { + if (Moves.Any(z => z > pk.MaxMoveID)) + Moves = Moves.Where(z => z <= pk.MaxMoveID).ToArray(); if (Moves.Length != 4) Array.Resize(ref Moves, 4); @@ -309,8 +311,8 @@ public static int GetSaneGender(this PKM pkm, int cg) /// details to copy from. public static void ApplySetDetails(this PKM pk, ShowdownSet Set) { - pk.Species = Set.Species; - pk.Moves = Set.Moves; + pk.Species = Math.Min(pk.MaxSpeciesID, Set.Species); + pk.SetMoves(Set.Moves, true); pk.ApplyHeldItem(Set.HeldItem, Set.Format); pk.CurrentLevel = Set.Level; pk.CurrentFriendship = Set.Friendship; @@ -382,6 +384,9 @@ public static void ApplyHeldItem(this PKM pk, int item, int format) case 1: pk.HeldItem = 0; break; default: pk.HeldItem = item; break; } + + if (pk.HeldItem > pk.MaxItemID) + pk.HeldItem = 0; } ///