Ejemplo n.º 1
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            LegalInfo info       = new LegalInfo(pkm);
            var       encounters = EncounterGenerator.GetEncounters(pkm, info);

            using (var encounter = new PeekEnumerator <IEncounterable>(encounters.GetEnumerator()))
            {
                if (!encounter.PeekIsNext())
                {
                    return(VerifyWithoutEncounter(pkm, info));
                }

                var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);
                while (encounter.MoveNext())
                {
                    info.EncounterMatch = encounter.Current;
                    var e = EncounterValidator(pkm, info);
                    if (!e.Valid && encounter.PeekIsNext())
                    {
                        info.Reject(e);
                        continue;
                    }
                    info.Parse.Add(e);

                    if (VerifySecondaryChecks(pkm, info, encounter))
                    {
                        break; // passes
                    }
                }
                return(info);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <param name="info">Object to store matched encounter info</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static void FindVerifiedEncounter(PKM pkm, LegalInfo info)
        {
            var encounters = EncounterGenerator.GetEncounters(pkm, info);

            using var encounter = new PeekEnumerator <IEncounterable>(encounters);
            if (!encounter.PeekIsNext())
            {
                VerifyWithoutEncounter(pkm, info);
                return;
            }

            var first = encounter.Current;
            var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(first.Generation);

            while (encounter.MoveNext())
            {
                var enc = encounter.Current;

                // Check for basic compatibility.
                var e = EncounterValidator(pkm, enc);
                if (!e.Valid && encounter.PeekIsNext())
                {
                    info.Reject(e);
                    continue;
                }

                // Looks like we might have a good enough match. Check if this is really a good match.
                info.EncounterMatch = enc;
                info.Parse.Add(e);
                if (!VerifySecondaryChecks(pkm, info, encounter))
                {
                    continue;
                }

                // Sanity Check -- Some secondary checks might not be as thorough as the partial-match leak-through checks done by the encounter.
                if (enc is not IEncounterMatch mx)
                {
                    break;
                }

                var match = mx.GetMatchRating(pkm);
                if (match != EncounterMatchRating.PartialMatch)
                {
                    break;
                }

                // Reaching here implies the encounter wasn't valid. Try stepping to the next encounter.
                if (encounter.PeekIsNext())
                {
                    continue;
                }

                // We ran out of possible encounters without finding a suitable match; add a message indicating that the encounter is not a complete match.
                info.Parse.Add(new CheckResult(Severity.Invalid, LEncInvalid, CheckIdentifier.Encounter));
                break;
            }

            if (!info.FrameMatches && info.EncounterMatch is EncounterSlot {
                Version : not GameVersion.CXD
            })                                                                                                                  // if false, all valid RNG frame matches have already been consumed
Ejemplo n.º 3
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            var info       = new LegalInfo(pkm);
            var encounters = EncounterGenerator.GetEncounters(pkm, info);

            using var encounter = new PeekEnumerator <IEncounterable>(encounters);
            if (!encounter.PeekIsNext())
            {
                return(VerifyWithoutEncounter(pkm, info));
            }

            var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);

            while (encounter.MoveNext())
            {
                info.EncounterMatch = encounter.Current;
                var e = EncounterValidator(pkm, info);
                if (!e.Valid && encounter.PeekIsNext())
                {
                    info.Reject(e);
                    continue;
                }
                info.Parse.Add(e);

                if (VerifySecondaryChecks(pkm, info, encounter))
                    break; // passes
            }

            if (!info.FrameMatches && info.EncounterMatch is EncounterSlot {
                Version : not GameVersion.CXD
            })                                                                                                                  // if false, all valid RNG frame matches have already been consumed
Ejemplo n.º 4
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <param name="info">Object to store matched encounter info</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static void FindVerifiedEncounter(PKM pkm, LegalInfo info)
        {
            var encounters = EncounterGenerator.GetEncounters(pkm, info);

            using var encounter = new PeekEnumerator <IEncounterable>(encounters);
            if (!encounter.PeekIsNext())
            {
                VerifyWithoutEncounter(pkm, info);
                return;
            }

            var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);

            while (encounter.MoveNext())
            {
                info.EncounterMatch = encounter.Current;
                var e = EncounterValidator(pkm, info);
                if (!e.Valid && encounter.PeekIsNext())
                {
                    info.Reject(e);
                    continue;
                }
                info.Parse.Add(e);

                if (!VerifySecondaryChecks(pkm, info, encounter))
                {
                    continue;
                }

                // Sanity Check -- Some secondary checks might not be as thorough as the partial-match leak-through checks done by the encounter.
                if (info.EncounterMatch is not IEncounterMatch mx)
                {
                    break;
                }

                var match = mx.GetMatchRating(pkm);
                if (match != EncounterMatchRating.PartialMatch)
                {
                    break;
                }

                if (encounter.PeekIsNext())
                {
                    continue;
                }

                info.Parse.Add(new CheckResult(Severity.Invalid, LEncInvalid, CheckIdentifier.Encounter));
                break;
            }

            if (!info.FrameMatches && info.EncounterMatch is EncounterSlot {
                Version : not GameVersion.CXD
            })                                                                                                                  // if false, all valid RNG frame matches have already been consumed
Ejemplo n.º 5
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            LegalInfo info       = new LegalInfo(pkm);
            var       encounters = EncounterGenerator.GetEncounters(pkm, info);

            using (var encounter = new PeekEnumerator <IEncounterable>(encounters))
            {
                if (!encounter.PeekIsNext())
                {
                    return(VerifyWithoutEncounter(pkm, info));
                }

                var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);
                while (encounter.MoveNext())
                {
                    info.EncounterMatch = encounter.Current;
                    var e = EncounterValidator(pkm, info);
                    if (!e.Valid && encounter.PeekIsNext())
                    {
                        info.Reject(e);
                        continue;
                    }
                    info.Parse.Add(e);

                    if (VerifySecondaryChecks(pkm, info, encounter))
                    {
                        break; // passes
                    }
                }

                if (!info.FrameMatches && info.EncounterMatch is EncounterSlot && pkm.Version != (int)GameVersion.CXD) // if false, all valid RNG frame matches have already been consumed
                {
                    info.Parse.Add(new CheckResult(Severity.Fishy, LEncConditionBadRNGFrame, CheckIdentifier.PID));    // todo for further confirmation
                }
                if (!info.PIDIVMatches)                                                                                // if false, all valid PIDIV matches have already been consumed
                {
                    info.Parse.Add(new CheckResult(Severity.Invalid, LPIDTypeMismatch, CheckIdentifier.PID));
                }

                return(info);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Iterates through all possible encounters until a sufficient match is found
        /// </summary>
        /// <remarks>
        /// The iterator lazily finds matching encounters, then verifies secondary checks to weed out any nonexact matches.
        /// </remarks>
        /// <param name="pkm">Source data to find a match for</param>
        /// <returns>
        /// Information containing the matched encounter and any parsed checks.
        /// If no clean match is found, the last checked match is returned.
        /// If no match is found, an invalid encounter object is returned.
        /// </returns>
        public static LegalInfo FindVerifiedEncounter(PKM pkm)
        {
            LegalInfo info       = new LegalInfo(pkm);
            var       encounters = EncounterGenerator.GetEncounters(pkm, info);

            using (var encounter = new PeekEnumerator <IEncounterable>(encounters.GetEnumerator()))
            {
                if (!encounter.PeekIsNext())
                {
                    return(VerifyWithoutEncounter(pkm, info));
                }

                var EncounterValidator = EncounterVerifier.GetEncounterVerifierMethod(pkm);
                while (encounter.MoveNext())
                {
                    info.EncounterMatch = encounter.Current;
                    var e = EncounterValidator(pkm, info);
                    if (!e.Valid && encounter.PeekIsNext())
                    {
                        info.Reject(e);
                        continue;
                    }
                    info.Parse.Add(e);

                    if (VerifySecondaryChecks(pkm, info, encounter))
                    {
                        break; // passes
                    }
                }

                if (!info.PIDIVMatches) // if false, all valid PIDIV matches have already been consumed
                {
                    info.Parse.Add(new CheckResult(Severity.Invalid, V411, CheckIdentifier.PID));
                }

                return(info);
            }
        }