From b89c4fb17fd43151b9d1c7bc151738140af40d66 Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 21 Apr 2021 18:33:57 -0700 Subject: [PATCH] Database load on invalid party counts --- PKHeX.Core/Saves/SaveFile.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 254a9f7a7..b8028ff51 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -282,18 +282,24 @@ public bool IsPartyAllEggs(params int[] except) return party.Count == party.Where(t => t.Species != 0).Where((t, i) => t.IsEgg || except.Contains(i)).Count(); } + private const int MaxPartyCount = 6; + public IList PartyData { get { - PKM[] data = new PKM[PartyCount]; + var count = PartyCount; + if (count > MaxPartyCount) + count = MaxPartyCount; + + PKM[] data = new PKM[count]; for (int i = 0; i < data.Length; i++) data[i] = GetPartySlot(PartyBuffer, GetPartyOffset(i)); return data; } set { - if (value.Count is 0 or > 6) + if (value.Count is 0 or > MaxPartyCount) throw new ArgumentException($"Expected 1-6, got {value.Count}"); #if DEBUG if (value[0].Species == 0)