From 6bd0e87ea3da92d6ad0bb4902cae5fefcbd82a4f Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 8 Jan 2019 16:45:16 -0800 Subject: [PATCH] Fix copyto discarding elements don't continue; instead seek forward #2235 part 1, need surgery for part 2 (starter/locked prevents writing data to the slot, but the slot can still be swapped) --- PKHeX.Core/PKM/Util/PKX.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/PKHeX.Core/PKM/Util/PKX.cs b/PKHeX.Core/PKM/Util/PKX.cs index 3a1fb9b11..edc7ee4e9 100644 --- a/PKHeX.Core/PKM/Util/PKX.cs +++ b/PKHeX.Core/PKM/Util/PKX.cs @@ -837,16 +837,26 @@ public static string GetLocationString(this PKM pk, bool eggmet) public static int CopyTo(this IEnumerable list, IList dest, Func skip, int start = 0) { int ctr = start; + if (ctr >= dest.Count) + return 0; + + int skipped = 0; foreach (var z in list) { + // seek forward to next open slot + while (true) + { + var exist = dest[ctr]; + if (exist == null || !skip(exist.Box, exist.Slot)) + break; + skipped++; + ctr++; + } if (dest.Count <= ctr) break; - var exist = dest[ctr]; - if (exist != null && skip(exist.Box, exist.Slot)) - continue; dest[ctr++] = z; } - return ctr - start; + return ctr - start - skipped; } ///