From dfa92e79b77ba7ab03ac8f3db8f0bf86057f82d8 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 9 Nov 2016 17:52:38 -0800 Subject: [PATCH] Fix NullReferenceException in legality checks --- PKHeX/Legality/Analysis.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PKHeX/Legality/Analysis.cs b/PKHeX/Legality/Analysis.cs index 331d2f021..dd2e11a3c 100644 --- a/PKHeX/Legality/Analysis.cs +++ b/PKHeX/Legality/Analysis.cs @@ -9,6 +9,12 @@ public partial class LegalityAnalysis private PKM pkm; private readonly List Parse = new List(); + private enum Encounters + { + Unknown = -1, + Generic = 0 + } + private object EncounterMatch; private Type EncounterType; private bool EncounterIsMysteryGift => EncounterType.IsSubclassOf(typeof (MysteryGift)); @@ -95,6 +101,10 @@ private void updateMoveLegality() private void updateChecks() { Encounter = verifyEncounter(); + + // If EncounterMatch is null, nullrefexception will prevent a lot of analysis from happening at all. + EncounterMatch = EncounterMatch ?? Encounters.Unknown; + EncounterType = EncounterMatch?.GetType(); if (EncounterType == typeof (MysteryGift)) EncounterType = EncounterType.BaseType;