Ejemplo n.º 1
0
        private async Task WalkInLine(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                var attempts = await StepUntilEncounter(token).ConfigureAwait(false);

                if (attempts < 0) // aborted
                {
                    continue;
                }

                Log($"Encounter found after {attempts} attempts! Checking details.");

                var pk = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false);

                if (pk.Species == 0)
                {
                    Log("Invalid data detected. Restarting loop.");
                    // add stuff for recovering
                    continue;
                }

                encounterCount++;
                Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
                Counts.AddCompletedEncounters();

                if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
                {
                    DumpPokemon(DumpSetting.DumpFolder, "encounters", pk);
                }

                if (StopCondition(pk))
                {
                    Log("Result found! Stopping routine execution; restart the bot(s) to search again.");
                    return;
                }
                else if (pk.Ability == 119 || pk.Ability == 107) // pokemon with announced abilites
                {
                    await Task.Delay(2700, token).ConfigureAwait(false);
                }

                await Task.Delay(2600, token).ConfigureAwait(false);

                while (await IsInBattle(token).ConfigureAwait(false))
                {
                    await FleeToOverworld(token).ConfigureAwait(false);
                }

                if (Mode == EncounterMode.VerticalLine)
                {
                    await SetStick(LEFT, 0, -30000, 2500, token).ConfigureAwait(false);
                }
                else if (Mode == EncounterMode.HorizontalLine)
                {
                    await SetStick(LEFT, -30000, 0, 2500, token).ConfigureAwait(false);
                }

                await ResetStick(token).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token)
        {
            encounterCount++;
            Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
            if (legends)
            {
                Counts.AddCompletedLegends();
            }
            else
            {
                Counts.AddCompletedEncounters();
            }

            if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
            {
                DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk);
            }

            if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions))
            {
                Log("Result found! Stopping routine execution; restart the bot(s) to search again.");
                if (Hub.Config.StopConditions.CaptureVideoClip)
                {
                    await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo, token).ConfigureAwait(false);
                    await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false);
                }
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private async Task WalkInLine(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                var attempts = await StepUntilEncounter(token).ConfigureAwait(false);

                if (attempts < 0) // aborted
                {
                    continue;
                }

                Log($"Encounter found after {attempts} attempts! Checking details...");

                // Reset stick while we wait for the encounter to load.
                await ResetStick(token).ConfigureAwait(false);

                var pk = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false);

                if (pk.Species == 0)
                {
                    Log("Invalid data detected. Restarting loop.");

                    // Flee and continue looping.
                    while (await IsInBattle(token).ConfigureAwait(false))
                    {
                        await FleeToOverworld(token).ConfigureAwait(false);
                    }
                    continue;
                }

                encounterCount++;
                Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
                Counts.AddCompletedEncounters();

                if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
                {
                    DumpPokemon(DumpSetting.DumpFolder, "encounters", pk);
                }

                if (StopCondition(pk))
                {
                    Log("Result found! Stopping routine execution; restart the bot(s) to search again.");
                    return;
                }

                // In some areas, the menu offset can flicker undesirably while battle is loading.
                await Task.Delay(4_000, token).ConfigureAwait(false);

                await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 15_000, 0_100, true, token).ConfigureAwait(false);

                Log("Running away...");
                while (await IsInBattle(token).ConfigureAwait(false))
                {
                    await FleeToOverworld(token).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 4
0
        private async Task WalkInLine(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                var attempts = await StepUntilEncounter(token).ConfigureAwait(false);

                if (attempts < 0) // aborted
                {
                    continue;
                }

                Log($"Encounter found after {attempts} attempts! Checking details.");

                // Reset stick while we wait for the encounter to load.
                await ResetStick(token).ConfigureAwait(false);

                var pk = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false);

                if (pk.Species == 0)
                {
                    Log("Invalid data detected. Restarting loop.");

                    // Flee and continue looping.
                    while (await IsInBattle(token).ConfigureAwait(false))
                    {
                        await FleeToOverworld(token).ConfigureAwait(false);
                    }
                    continue;
                }

                encounterCount++;
                Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
                Counts.AddCompletedEncounters();

                if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
                {
                    DumpPokemon(DumpSetting.DumpFolder, "encounters", pk);
                }

                if (StopCondition(pk))
                {
                    Log("Result found! Stopping routine execution; restart the bot(s) to search again.");
                    return;
                }
                if (EncounterBotUtil.DisplayedAbilities.Contains(pk.Ability)) // pokemon with announced abilites
                {
                    await Task.Delay(2_700, token).ConfigureAwait(false);
                }

                await Task.Delay(2_700, token).ConfigureAwait(false);

                while (await IsInBattle(token).ConfigureAwait(false))
                {
                    await FleeToOverworld(token).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 5
0
        private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token)
        {
            encounterCount++;

            //Star/Square Shiny Recognition
            var showdowntext = ShowdownParsing.GetShowdownText(pk);

            if (pk.IsShiny && pk.ShinyXor == 0)
            {
                showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Square");
            }
            else if (pk.IsShiny)
            {
                showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Star");
            }

            Log($"Encounter: {encounterCount}{Environment.NewLine}{Environment.NewLine}{showdowntext}{Environment.NewLine}{GetRibbonsList(pk)}{Environment.NewLine}");
            if (legends)
            {
                Counts.AddCompletedLegends();
            }
            else
            {
                Counts.AddCompletedEncounters();
            }

            if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
            {
                DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk);
                Counts.AddCompletedDumps();
            }

            if (StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions))
            {
                if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag) && Hub.Config.SWSH_Encounter.EncounteringType != EncounterMode.LiveStatsChecking)
                {
                    Log($"<@{Hub.Config.Discord.UserTag}> result found! Stopping routine execution; restart the bot(s) to search again.");
                }
                else if (Hub.Config.SWSH_Encounter.EncounteringType != EncounterMode.LiveStatsChecking)
                {
                    Log("Result found!");
                }
                if (Hub.Config.StopConditions.CaptureVideoClip)
                {
                    await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo, token).ConfigureAwait(false);
                    await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false);
                }
                return(true);
            }
            return(false);
        }
        private bool HandleEncounter(PK8 pk, bool legends)
        {
            encounterCount++;

            //Star/Square Shiny Recognition
            var showdowntext = ShowdownParsing.GetShowdownText(pk);

            if (pk.IsShiny && pk.ShinyXor == 0)
            {
                showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Square");
            }
            else if (pk.IsShiny)
            {
                showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Star");
            }

            Log($"Encounter: {encounterCount}{Environment.NewLine}{Environment.NewLine}{showdowntext}{Environment.NewLine}");
            if (legends)
            {
                Counts.AddCompletedLegends();
            }
            else
            {
                Counts.AddCompletedEncounters();
            }

            if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
            {
                DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk);
                Counts.AddCompletedDumps();
            }

            if (StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions))
            {
                if (legends)
                {
                    Log("Result found! Stopping routine execution; restart the bot(s) to search again.");
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token)
        {
            encounterCount++;
            Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownParsing.GetShowdownText(pk)}{Environment.NewLine}{(StopConditionSettings.HasMark(pk, out RibbonIndex mark) ? $"Mark: {mark.ToString().Replace("Mark", "")}{Environment.NewLine}" : "")}");
            TradeExtensions.EncounterLogs(pk);
            if (legends)
            {
                Counts.AddCompletedLegends();
            }
            else
            {
                Counts.AddCompletedEncounters();
            }

            if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
            {
                DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk);
            }

            if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions))
            {
                Log(Hub.Config.StopConditions.CatchEncounter && (Hub.Config.Encounter.EncounteringType == EncounterMode.VerticalLine || Hub.Config.Encounter.EncounteringType == EncounterMode.HorizontalLine) ?
                    "Result found! Attempting to catch..." : $"{(!Hub.Config.StopConditions.PingOnMatch.Equals(string.Empty) ? $"<@{Hub.Config.StopConditions.PingOnMatch}>\n" : "")}Result found! Stopping routine execution; restart the bot(s) to search again.");
                if (Hub.Config.StopConditions.CaptureVideoClip)
                {
                    await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo, token).ConfigureAwait(false);
                    await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false);
                }

                if (Hub.Config.StopConditions.CatchEncounter && (Hub.Config.Encounter.EncounteringType == EncounterMode.VerticalLine || Hub.Config.Encounter.EncounteringType == EncounterMode.HorizontalLine))
                {
                    await CatchWildPokemon(pk, token).ConfigureAwait(false);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token)
        {
            encounterCount++;
            Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
            Counts.AddEncounteredSpecies(pk);
            if (legends)
            {
                Counts.AddCompletedLegends();
            }
            else
            {
                Counts.AddCompletedEncounters();
            }

            if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
            {
                DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk);
            }

            if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions))
            {
                Log(!Hub.Config.StopConditions.CatchEncounter || Hub.Config.Encounter.EncounteringType == EncounterMode.StrongSpawn ? $"{Ping}Result found! Stopping routine execution; restart the bot(s) to search again." : "Result found! Attempting to catch...");
                if (Hub.Config.StopConditions.CaptureVideoClip)
                {
                    await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo).ConfigureAwait(false);
                    await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false);
                }

                if (Hub.Config.StopConditions.CatchEncounter && (Hub.Config.Encounter.EncounteringType == EncounterMode.VerticalLine || Hub.Config.Encounter.EncounteringType == EncounterMode.HorizontalLine))
                {
                    await CatchWildPokemon(pk, token).ConfigureAwait(false);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 9
0
        private async Task WalkInLine(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                var attempts = await StepUntilEncounter(token).ConfigureAwait(false);

                if (attempts < 0) // aborted
                {
                    continue;
                }

                Log($"Encounter found after {attempts} attempts! Checking details...");

                // Reset stick while we wait for the encounter to load.
                await ResetStick(token).ConfigureAwait(false);

                var pk = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false);

                if (pk.Species == 0)
                {
                    Log("Invalid data detected. Restarting loop.");

                    // Flee and continue looping.
                    while (await IsInBattle(token).ConfigureAwait(false))
                    {
                        await FleeToOverworld(token).ConfigureAwait(false);
                    }
                    continue;
                }

                encounterCount++;
                Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
                Counts.AddCompletedEncounters();

                if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
                {
                    DumpPokemon(DumpSetting.DumpFolder, "encounters", pk);
                }

                // Offsets are flickery so make sure we see it 3 times.
                for (int i = 0; i < 3; i++)
                {
                    await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
                }

                if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions))
                {
                    Log("Result found! Stopping routine execution; restart the bot(s) to search again.");
                    if (Hub.Config.StopConditions.CaptureVideoClip)
                    {
                        await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo).ConfigureAwait(false);
                        await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false);
                    }
                    return;
                }

                Log("Running away...");
                while (await IsInBattle(token).ConfigureAwait(false))
                {
                    await FleeToOverworld(token).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 10
0
        private async Task WalkInLine(CancellationToken token)
        {
            if (hub.Config.Encounter.CatchEncounter && !hub.Config.Encounter.StrongSpawn)
            {
                Log("Checking Poké Ball count...");
                pouchData = await Connection.ReadBytesAsync(PokeBallOffset, 116, token).ConfigureAwait(false);

                var counts = EncounterCount.GetBallCounts(pouchData);
                catchCount = counts.PossibleCatches(Ball.Master);

                if (catchCount == 0)
                {
                    Log("Insufficient Master Balls. Please obtain at least one before starting.");
                    return;
                }
            }

            while (!token.IsCancellationRequested)
            {
                if (hub.Config.Encounter.StrongSpawn)
                {
                    await StrongSpawn(token).ConfigureAwait(false);
                }

                var attempts = await StepUntilEncounter(token).ConfigureAwait(false);

                if (attempts < 0) // aborted
                {
                    continue;
                }

                Log($"Encounter found after {attempts} attempts! Checking details...");

                // Reset stick while we wait for the encounter to load.
                await ResetStick(token).ConfigureAwait(false);

                var pk = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false);

                if (pk.Species == 0)
                {
                    Log("Invalid data detected. Restarting loop.");

                    // Flee and continue looping.
                    while (await IsInBattle(token).ConfigureAwait(false))
                    {
                        await FleeToOverworld(token).ConfigureAwait(false);
                    }
                    continue;
                }

                encounterCount++;
                Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
                Counts.AddCompletedEncounters();
                Counts.AddEncounteredSpecies(pk);

                if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
                {
                    DumpPokemon(DumpSetting.DumpFolder, "encounters", pk);
                }

                // Offsets are flickery so make sure we see it 3 times.
                for (int i = 0; i < 3; i++)
                {
                    await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
                }

                if (StopCondition(pk))
                {
                    if (hub.Config.CaptureVideoClip)
                    {
                        await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false);
                    }

                    if (hub.Config.Encounter.CatchEncounter && !hub.Config.Encounter.StrongSpawn)
                    {
                        await SetLastUsedBall(Ball.Master, token).ConfigureAwait(false);

                        Log($"Result found! Attempting to catch...");
                        await CatchWildPokemon(pk, token).ConfigureAwait(false);

                        if (!hub.Config.Encounter.InjectPokeBalls && encounterCount != 0 && encounterCount % catchCount == 0)
                        {
                            return;
                        }

                        await WalkInLine(token).ConfigureAwait(false);
                    }

                    Log($"{Ping}Result found! Stopping routine execution; restart the bot(s) to search again.");
                    return;
                }

                Log("Running away...");
                while (await IsInBattle(token).ConfigureAwait(false) && !hub.Config.Encounter.StrongSpawn)
                {
                    await FleeToOverworld(token).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 11
0
        private async Task Overworld(CancellationToken token, bool birds = false)
        {
            GameVersion version = await LGWhichGameVersion(token).ConfigureAwait(false);

            List <int[]> movementslist = ParseMovements();
            bool         firstrun      = movementslist.Count > 0;
            Stopwatch    stopwatch     = new Stopwatch();
            uint         prev          = 0;
            uint         newspawn;
            uint         catchcombo;
            uint         speciescombo;
            int          i              = 0;
            int          j              = 0;
            bool         freeze         = false;
            bool         searchforshiny = Hub.Config.LGPE_OverworldScan.OnlyShiny;
            bool         found          = false;

            if (movementslist.Count > 0)
            {
                Log($"ATTENTION!{Environment.NewLine}Any wild encounter will broke the movement routine, resulting in the pg moving to unwanted places!{Environment.NewLine}" +
                    $"----------------------------------------{Environment.NewLine}" +
                    $"ATTENTION!\nUnexpected behaviour can occur if a shiny is detected while changing area. It his higlhy recommended to avoid that.{Environment.NewLine}" +
                    $"-----------------------------------------{Environment.NewLine}");
            }

            //Catch combo to increment spawn quality and shiny rate (Thanks to Lincoln-LM for the offsets)
            if ((int)Hub.Config.LGPE_OverworldScan.ChainSpecies > 0)
            {
                speciescombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0);
                if ((speciescombo != (uint)Hub.Config.LGPE_OverworldScan.ChainSpecies) && (Hub.Config.LGPE_OverworldScan.ChainSpecies != 0))
                {
                    Log($"Current catch combo being on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}, changing to {Hub.Config.LGPE_OverworldScan.ChainSpecies}.");
                    await SwitchConnection.WriteBytesAbsoluteAsync(BitConverter.GetBytes((uint)Hub.Config.LGPE_OverworldScan.ChainSpecies), await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), token).ConfigureAwait(false);

                    speciescombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0);
                    Log($"Current catch combo being now on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}.");
                }
            }
            if (Hub.Config.LGPE_OverworldScan.ChainCount > 0)
            {
                catchcombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0);
                if (catchcombo < (uint)Hub.Config.LGPE_OverworldScan.ChainCount)
                {
                    Log($"Current catch combo being {catchcombo}, incrementing to {Hub.Config.LGPE_OverworldScan.ChainCount}.");
                    await SwitchConnection.WriteBytesAbsoluteAsync(BitConverter.GetBytes((uint)Hub.Config.LGPE_OverworldScan.ChainCount), await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), token).ConfigureAwait(false);

                    catchcombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0);
                    Log($"Current catch combo being now {catchcombo}.");
                }
            }

            while (!token.IsCancellationRequested)
            {
                if (searchforshiny)
                {
                    await LGZaksabeast(token, version).ConfigureAwait(false);
                }
                while (freeze == false && !token.IsCancellationRequested && !found)
                {
                    if (await LGCountMilliseconds(Hub.Config, token).ConfigureAwait(false) > 0 || !searchforshiny)
                    {
                        //The routine need to continue and check the overworld spawns, cannot be stuck at changing stick position.
                        if (movementslist.Count > 0)
                        {
                            if (stopwatch.ElapsedMilliseconds >= movementslist.ElementAt(j)[2] || firstrun)
                            {
                                if (firstrun)
                                {
                                    firstrun = false;
                                }
                                //Log($"Moved for {stopwatch.ElapsedMilliseconds}ms.");
                                await ResetStick(token).ConfigureAwait(false);
                                await SetStick(RIGHT, (short)(movementslist.ElementAt(j)[0]), (short)(movementslist.ElementAt(j)[1]), 0_001, token).ConfigureAwait(false);

                                j++;
                                if (j == movementslist.Count)
                                {
                                    j = 0;
                                }
                                stopwatch.Restart();
                            }
                        }

                        //Check is inside an unwanted encounter
                        if (await LGIsInCatchScreen(token).ConfigureAwait(false))
                        {
                            await ResetStick(token).ConfigureAwait(false);

                            Log($"Unwanted encounter detected!");
                            int y = 0;
                            while (await LGIsInCatchScreen(token).ConfigureAwait(false) && !token.IsCancellationRequested)
                            {
                                y++;
                                await Task.Delay(8_000, token).ConfigureAwait(false);

                                if (y > 2)
                                {
                                    await Click(B, 1_200, token).ConfigureAwait(false);
                                }
                                await Click(B, 1_200, token).ConfigureAwait(false);
                                await Click(A, 1_000, token).ConfigureAwait(false);

                                await Task.Delay(6_500, token).ConfigureAwait(false);
                            }
                            Log($"Exited wild encounter.");
                        }

                        //Check new spawns
                        newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn1, 2, token).ConfigureAwait(false), 0);
                        if (newspawn != prev)
                        {
                            if (newspawn != 0)
                            {
                                i++;
                                if (IsPKLegendary((int)newspawn))
                                {
                                    Counts.AddCompletedLegends();
                                }
                                else
                                {
                                    Counts.AddCompletedEncounters();
                                }
                                Log($"New spawn ({i}): {newspawn} {SpeciesName.GetSpeciesName((int)newspawn, 4)}");
                            }
                            prev = newspawn;
                            if (!searchforshiny &&
                                ((!birds && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) ||
                                 (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0) ||
                                 (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146))))
                            {
                                await Click(X, 1_000, token).ConfigureAwait(false);
                                await Click(HOME, 1_000, token).ConfigureAwait(false);

                                if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag))
                                {
                                    Log($"<@{Hub.Config.Discord.UserTag}> stop conditions met, restart the bot(s) to search again.");
                                }
                                else
                                {
                                    Log("Stop conditions met, restart the bot(s) to search again.");
                                }
                                return;
                            }
                        }
                    }
                    else if (searchforshiny)
                    {
                        freeze = true;
                    }
                }

                if (searchforshiny && !token.IsCancellationRequested)
                {
                    Log("A Shiny has been detected.");
                }

                //Unfreeze to restart the routine, or log the Shiny species.
                await LGUnfreeze(token, version).ConfigureAwait(false);

                newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn1, 2, token).ConfigureAwait(false), 0);

                //Stop Conditions logic
                if (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146) && !token.IsCancellationRequested)
                {
                    found = true;
                }
                else if ((!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies > 0 && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) ||
                         (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0))
                {
                    found = true;
                }
                else
                {
                    found = false;
                }

                if (!found && !token.IsCancellationRequested)
                {
                    freeze = false;
                    Log($"Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} is not the target, the routine will continue.");
                }
                else if (!token.IsCancellationRequested)
                {
                    await ResetStick(token).ConfigureAwait(false);

                    if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag))
                    {
                        Log($"<@{Hub.Config.Discord.UserTag}> Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!");
                    }
                    else
                    {
                        Log($"Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!");
                    }
                    await Click(X, 1_000, token).ConfigureAwait(false);
                    await Click(HOME, 1_000, token).ConfigureAwait(false);

                    return;
                }
            }
            await ResetStick(token).ConfigureAwait(false);

            if (searchforshiny)
            {
                await LGUnfreeze(token, version).ConfigureAwait(false);
            }
        }