Exemple #1
0
        public async Task DetachAsync()
        {
            await ReplyAsync("A controller detach request will be executed momentarily.").ConfigureAwait(false);

            var bot = Globals.Bot;
            await bot.Connection.SendAsync(SwitchCommand.DetachController(), CancellationToken.None).ConfigureAwait(false);
        }
Exemple #2
0
        public override async Task MainLoop(CancellationToken token)
        {
            Log("Identifying trainer data of the host console.");
            var sav = await IdentifyTrainer(token).ConfigureAwait(false);

            Log("Detaching on startup.");
            await Connection.SendAsync(SwitchCommand.DetachController(), token).ConfigureAwait(false);

            await Task.Delay(0_200, token).ConfigureAwait(false);

            await Click(A, 0_100, token).ConfigureAwait(false);

            Log("Turning off screen.");
            await SetScreen(false, token).ConfigureAwait(false);

            Log("Starting main TradeBot loop.");
            while (!token.IsCancellationRequested)
            {
                Config.IterateNextRoutine();
                var task = Config.CurrentRoutineType switch
                {
                    PokeRoutineType.Idle => DoNothing(token),
                    PokeRoutineType.SurpriseTrade => DoSurpriseTrades(sav, token),
                    _ => DoTrades(sav, token),
                };
                await task.ConfigureAwait(false);
            }
            Hub.Bots.Remove(this);
        }
Exemple #3
0
        protected override async Task MainLoop(CancellationToken token)
        {
            // Disconnect our virtual controller; will reconnect once we send a button command after a request.
            LogUtil.LogInfo("Detaching controller on startup as first interaction.", Config.IP);
            await Connection.SendAsync(SwitchCommand.DetachController(), token);

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

            // Validate inventory offset.
            LogUtil.LogInfo("Checking inventory offset for validity.", Config.IP);
            var(ofs, len) = InventoryValidator.GetOffsetLength(Config.Offset);
            var inventory = await Connection.ReadBytesAsync(ofs, len, token).ConfigureAwait(false);

            bool valid = InventoryValidator.ValidateItemBinary(inventory);

            if (!valid)
            {
                LogUtil.LogInfo($"Inventory read from {Config.Offset} does not appear to be valid. Exiting!", Config.IP);
                return;
            }

            LogUtil.LogInfo("Successfully connected to bot. Starting main loop!", Config.IP);
            int dropCount = 0;
            int idleCount = 0;

            while (!token.IsCancellationRequested)
            {
                if (!Config.AcceptingCommands)
                {
                    await Task.Delay(1_000, token).ConfigureAwait(false);

                    continue;
                }

                if (Injections.TryDequeue(out var item))
                {
                    dropCount += await DropItems(item, token).ConfigureAwait(false);

                    idleCount = 0;
                }
                else if ((Config.AutoClean && dropCount != 0 && ++idleCount > 60) || CleanRequested)
                {
                    await CleanUp(token).ConfigureAwait(false);

                    dropCount      = 0;
                    idleCount      = 0;
                    CleanRequested = false;
                }
                else
                {
                    idleCount++;
                    await Task.Delay(1_000, token).ConfigureAwait(false);
                }
            }
        }
Exemple #4
0
        public static async Task <bool> ValidateStartup(Bot b, CancellationToken token)
        {
            // Validate our config file inputs.
            if (!ValidateConfigFileParameters(b))
            {
                return(false);
            }

            // Disconnect our virtual controller; will reconnect once we send a button command after a request.
            b.Log("Detaching controller on startup as first interaction.");
            await b.Connection.SendAsync(SwitchCommand.DetachController(b.UseCRLF), token).ConfigureAwait(false);

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

            // Validate inventory offset.
            var inventoryValid = await ValidateStartupInventory(b, token).ConfigureAwait(false);

            if (!inventoryValid)
            {
                return(false);
            }

            if (b.Config.VillagerConfig.AllowVillagerInjection)
            {
                await b.VillagerState.InitializeVillagers(token).ConfigureAwait(false);
            }

            if (b.Config.ViewConfig.SkipSessionCheck)
            {
                return(await StartupGetDodoCode(b.ViewState, b, token, true).ConfigureAwait(false));
            }

            var sessionActive = await b.ViewState.IsLinkSessionActive(token).ConfigureAwait(false);

            if (sessionActive)
            {
                return(await b.ViewState.StartupGetDodoCode(b, token, true).ConfigureAwait(false));
            }

            bool gates = await b.ViewState.StartupOpenGates(b, token).ConfigureAwait(false);

            return(gates && await b.ViewState.StartupGetDodoCode(b, token).ConfigureAwait(false));
        }
Exemple #5
0
 public void Detach()
 {
     Connection.CurrentConnection.SendBytes(SwitchCommand.DetachController());
 }