示例#1
0
        public void Bot()
        {
            // Start Horipad Emulator(InputRedirection)

            string RegistyKey           = "HKEY_CURRENT_USER\\SOFTWARE\\Mitsuki\\LinkBots";
            string RegistyBotReadyCount = "BotsReadyCount";
            string RegistyBotCount      = "BotsAmount";
            int    Bots         = 0;
            int    BotsAmount   = 0;
            bool   FirstStarted = true;

            Input = new SwitchInputSink(Port);
            int ConnectAttemps = 0;

            Program.form.ApplyLog($"Use Sync: {UseSync.ToString()} Reconnect After: {ReconnectAfter} Slot: {Slot} Link Code: {LinkCode}");

            while (!Program.botConnected)
            {
                if (ConnectAttemps >= 5)
                {
                    Program.form.ApplyLog("Can't connect to Device!");
                    Program.form.UpdateStatus("Failed to connect to Console!");
                    Program.botRunning   = false;
                    Program.botConnected = false;
                    break;
                }
                Input.BotWait(1000);
                ConnectAttemps++;
            }
            if (Program.botConnected && Program.botRunning)
            {
                if (UseSync)
                {
                    Program.form.ApplyLog("Bot Sync is Enabled!");
                }
                Program.form.ApplyLog("Starting Bot in 5 Seconds...");
                Input.SendButton(Button.B, 1000);
                Input.SendButton(Button.B, 1000);
                Input.SendButton(Button.B, 1000);
            }
            while (Program.botRunning)
            {
                try
                {
                    if (CurrentTrades > ReconnectAfter || FirstStarted)
                    {
                        //Reconnect if disconnected
                        Program.form.ApplyLog("Auto Reconnect is enabled, reconnecting if disconnected...");
                        // Open Y-COM
                        Program.form.ApplyLog("Open Y-COM Menu");
                        Input.SendButton(Button.Y, 2000);

                        //Press Plus, don't need a confirmation if not connected
                        Input.SendButton(Button.Plus, 2000);
                        Program.form.ApplyLog("Wait 20 Seconds to ensure we are connected");
                        //Wait 15 Seconds
                        Input.BotWait(20000);
                        Program.form.ApplyLog("Reconnected! Return to Overworld");
                        //Return to Overworld
                        Input.SendButton(Button.B, 1500);
                        Input.SendButton(Button.B, 1500);
                        CurrentTrades = 1;
                        FirstStarted  = false;
                    }


                    Program.form.ApplyLog("Open Y-COM Menu");
                    Input.SendButton(Button.Y, 2000);
                    Program.form.ApplyLog("Select Link Trade Trade");
                    Input.SendButton(Button.A, 1000);
                    Program.form.ApplyLog("Select Password");
                    Input.SendDpad(DPad.Down, 100);
                    Input.SendButton(Button.A, 1000);
                    Input.SendButton(Button.A, 1000);

                    /* German version needs 3 A Presses? */
                    if (IsGerman)
                    {
                        Input.SendButton(Button.A, 1000);
                    }

                    Input.BotWait(3000);
                    Program.form.ApplyLog("Enter Code: " + LinkCode);
                    SelectTradeCode(LinkCode);
                    Input.SendButton(Button.Plus, 100);

                    //Start a Link Trade, in case of Empty Slot/Egg/Bad Pokemon we press sometimes B to return to the Overworld and skip this Slot.
                    Program.form.ApplyLog("Confirming...");
                    Input.SendButton(Button.A, 2000);
                    Input.SendButton(Button.A, 2000);
                    Input.SendButton(Button.A, 2000);
                    Input.SendButton(Button.A, 2000);
                    Thread.Sleep(new Random().Next(100, 1000));
                    if (UseSync)
                    {
                        Bots       = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotReadyCount, 0).ToString());
                        BotsAmount = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotCount, 0).ToString());
                        // Increase BotReady Count
                        Program.form.ApplyLog("Waiting for other Bots...");
                        Bots++;

                        Registry.SetValue(RegistyKey, RegistyBotReadyCount, Bots.ToString(), RegistryValueKind.String);

                        while (Bots < BotsAmount)
                        {
                            try
                            {
                                // Get Registry Values for Bots
                                Bots = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotReadyCount, 0).ToString());

                                BotsAmount = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotCount, 0).ToString());
                            }
                            catch
                            {
                                break;
                            }
                            Thread.Sleep(100);
                        }
                        Program.form.ApplyLog("Bots are Ready!");
                    }
                    Thread.Sleep(new Random().Next(500, 2500));

                    Input.SendButton(Button.A, 1000);
                    Program.form.ApplyLog("Wait 30 Seconds for Trainer...");
                    Input.BotWait(40000);
                    Program.form.ApplyLog("Potential Trainer Found!");

                    Program.form.ApplyLog("Select Pokemon");
                    SelectBoxSlot(Box, Slot, 250);

                    Input.SendButton(Button.A, 2000);
                    Input.SendButton(Button.A, 2000);
                    Program.form.ApplyLog("Wait for User Input...");

                    for (int i = 0; i < 25; i++)
                    {
                        Input.SendButton(Button.A, 1000);
                    }

                    Input.SendButton(Button.A, 3000);
                    Program.form.ApplyLog("Link Trade Started, wait 10 seconds, abort after 15 Seconds!");
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);

                    Input.SendButton(Button.A, 1500);
                    Input.SendButton(Button.A, 1500);
                    Program.form.ApplyLog("Wait 30 Seconds until Trade is finished...");

                    Input.BotWait(30000 + new Random().Next(500, 5000));

                    Program.form.ApplyLog("Pokemon has been prolly arrived, bypass Trade Evolution...");
                    Input.SendButton(Button.Y, 1000);
                    Input.BotWait(1000 + new Random().Next(500, 5000));

                    for (int i = 0; i < 10; i++)
                    {
                        Input.SendButton(Button.B, 1000);
                        Input.SendButton(Button.B, 1000);
                        Input.SendButton(Button.A, 1000);
                    }
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);

                    // Spam A Button for 40 seconds in Case of Trade Evolution/Moves Learnings/Dex
                    for (int ii = 0; ii < 20; ii++)
                    {
                        Input.SendButton(Button.A, 1000);
                    }

                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Program.form.ApplyLog("Trade was Successfull!");

                    if (Slot > 29)
                    {
                        Box++;
                        Slot = 1;
                    }
                    else
                    {
                        Slot++;
                    }
                    CurrentTrades++;
                }
                catch
                {
                    Program.form.ApplyLog("Bot lost connection to Host, check your cable connected!");
                    Program.form.UpdateStatus("Disconnected! | Can't connect to Host!");
                }
                Thread.Sleep(100);
            }
            Program.form.ApplyLog("Bot Stopped!");
        }
        public void Bot()
        {
            // Start Horipad Emulator(InputRedirection)

            string RegistyKey           = "HKEY_CURRENT_USER\\SOFTWARE\\Mitsuki\\WTBots";
            string RegistyBotReadyCount = "BotsReadyCount";
            string RegistyBotCount      = "BotsAmount";
            int    Bots         = 0;
            int    BotsAmount   = 0;
            bool   FirstStarted = true;

            Program.form.ApplyLog($"Use Sync: {UseSync.ToString()} Reconnect After: {ReconnectAfter} Slot: {Slot} Show Pokemon: {ShowPokemon}");


            Input = new SwitchInputSink(Port);
            int ConnectAttemps = 0;

            while (!Program.botConnected)
            {
                if (ConnectAttemps > 5)
                {
                    Program.form.ApplyLog("Can't connect to Device!");
                    Program.form.UpdateStatus("Failed to connect to Console!");
                    Program.botRunning   = false;
                    Program.botConnected = false;
                    break;
                }
                Input.BotWait(1000);
                ConnectAttemps++;
            }
            if (Program.botConnected && Program.botRunning)
            {
                if (UseSync)
                {
                    Program.form.ApplyLog("Bot Sync is Enabled!");
                }
                Program.form.ApplyLog("Starting Bot in 5 Seconds...");
                Input.SendButton(Button.B, 1000);
                Input.SendButton(Button.B, 1000);
                Input.SendButton(Button.B, 1000);
            }
            while (Program.botRunning)
            {
                try
                {
                    if (CurrentTrades > ReconnectAfter || FirstStarted)
                    {
                        //Reconnect if disconnected
                        Program.form.ApplyLog("Auto Reconnect is enabled, reconnecting if disconnected...");
                        // Open Y-COM
                        Program.form.ApplyLog("Open Y-COM Menu");
                        Input.SendButton(Button.Y, 2000);

                        //Press Plus, don't need a confirmation if not connected
                        Input.SendButton(Button.Plus, 2000);
                        Program.form.ApplyLog("Wait 15 Seconds to ensure we are connected");
                        //Wait 15 Seconds
                        Input.BotWait(15000);
                        Program.form.ApplyLog("Reconnected! Return to Overworld");
                        //Return to Overworld
                        Input.SendButton(Button.B, 1500);
                        Input.SendButton(Button.B, 1500);
                        CurrentTrades = 1;
                        FirstStarted  = false;
                    }


                    Program.form.ApplyLog("Open Y-COM Menu");
                    Input.SendButton(Button.Y, 2000);
                    Program.form.ApplyLog("Select Suprise Trade");
                    Input.SendDpad(DPad.Down, 100);
                    Input.SendButton(Button.A, 1000);
                    Input.BotWait(3000);

                    Program.form.ApplyLog("Select Pokemon");
                    SelectBoxSlot(Box, Slot, 250);

                    Input.SendButton(Button.A, 2000);

                    if (ShowPokemon)
                    {
                        Program.form.ApplyLog("Show Pokemon is enabled, wait 15 Seconds...");
                        Input.BotWait(new Random().Next(13000, 15000));
                    }
                    //Start a Suprise Trade, in case of Empty Slot/Egg/Bad Pokemon we press sometimes B to return to the Overworld and skip this Slot.
                    Program.form.ApplyLog("Confirming...");
                    Input.SendButton(Button.A, 1000);
                    Input.SendButton(Button.A, 3000);
                    Input.SendButton(Button.A, 1000);
                    Input.SendButton(Button.A, 2000);
                    if (UseSync)
                    {
                        Bots       = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotReadyCount, 0).ToString());
                        BotsAmount = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotCount, 0).ToString());
                        // Increase BotReady Count
                        Program.form.ApplyLog("Waiting for other Bots...");
                        Bots++;
                        Registry.SetValue(RegistyKey, RegistyBotReadyCount, Bots.ToString(), RegistryValueKind.String);


                        while (Bots < BotsAmount)
                        {
                            // Get Registry Values for Bots
                            Bots       = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotReadyCount, 0).ToString());
                            BotsAmount = Convert.ToInt16(Registry.GetValue(RegistyKey, RegistyBotCount, 0).ToString());

                            Input.BotWait(100);
                        }
                        Program.form.ApplyLog("Bots are Ready!");
                    }

                    Input.SendButton(Button.A, 3000);
                    Program.form.ApplyLog("Suprise Trade Started, wait 10 seconds...");
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);

                    Input.SendButton(Button.A, 1500);
                    Input.SendButton(Button.A, 1500);
                    Program.form.ApplyLog("Wait until Trade is finished, prevent auto disconnect by walking arround");

                    for (int BypassDisconnect = 0; BypassDisconnect < 35; BypassDisconnect++)
                    {
                        Input.SendAnalog(0, 128, 128, 128, 100);   // Left
                        Input.SendAnalog(-20, 128, 128, 128, 100); // Right
                    }
                    Input.BotWait(1000);

                    Program.form.ApplyLog("Pokemon has been arrived, bypass Trade Evolution...");
                    Input.SendButton(Button.Y, 1000);
                    Input.BotWait(1000);

                    Input.SendButton(Button.A, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.A, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);


                    for (int i = 0; i < 5; i++)
                    {
                        Input.SendButton(Button.A, 1000);
                    }

                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);

                    // Spam A Button for 40 seconds in Case of Trade Evolution/Moves Learnings/Dex
                    for (int ii = 0; ii < 40; ii++)
                    {
                        Input.SendButton(Button.A, 1000);
                    }

                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Input.SendButton(Button.B, 1000);
                    Program.form.ApplyLog("Trade was Successfull!");

                    if (Slot > 29)
                    {
                        Box++;
                        Slot = 1;
                    }
                    else
                    {
                        Slot++;
                    }
                    CurrentTrades++;
                }
                catch
                {
                    Program.form.ApplyLog("Bot lost connection to Host, check your cable connected!");
                    Program.form.UpdateStatus("Disconnected! | Can't connect to Host!");
                }
            }
            Program.form.ApplyLog("Bot Stopped!");
        }