From 8b0e93b42f1fe02eea257d6323fa1c2c94eae17a Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 14 Oct 2022 17:05:19 -0700 Subject: [PATCH] Fix GetLowestLevel underflow condition Check end before decrement Closes #3605 thanks @InfoManiac742 ! --- .../Legality/Encounters/Information/EncounterSuggestion.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs index 5b4fba065..0fefd8e9f 100644 --- a/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs +++ b/PKHeX.Core/Legality/Encounters/Information/EncounterSuggestion.cs @@ -103,14 +103,17 @@ public static class EncounterSuggestion var table = EvolutionTree.GetEvolutionTree(pk.Context); int count = 1; - for (byte i = 100; i >= startLevel; i--) + byte i = 100; + while (true) { var evos = table.GetValidPreEvolutions(pk, levelMax: i, skipChecks: true, levelMin: startLevel); if (evos.Length < count) // lost an evolution, prior level was minimum current level return GetMaxLevelMax(evos) + 1; count = evos.Length; + if (i == startLevel) + return startLevel; + --i; } - return startLevel; } private static int GetMaxLevelMax(EvoCriteria[] evos)