Example #1
0
        public async Task ReOpenGame(PokeTradeHubConfig config, CancellationToken token)
        {
            // Reopen the game if we get soft-banned
            Log("Potential soft ban detected, reopening game just in case!");
            await CloseGame(config, token).ConfigureAwait(false);
            await StartGame(config, token).ConfigureAwait(false);

            // In case we are soft banned, reset the timestamp
            await Unban(token).ConfigureAwait(false);
        }
Example #2
0
        public PokeTradeHub(PokeTradeHubConfig config)
        {
            Config = config;
            var pool = new PokemonPool <T>(config);

            Ledy    = new LedyDistributor <T>(pool);
            BotSync = new BotSynchronizer(config.Distribution);
            BotSync.BarrierReleasingActions.Add(() => LogUtil.LogInfo($"{BotSync.Barrier.ParticipantCount} bots released.", "Barrier"));

            Queues = new TradeQueueManager <T>(this);
        }
Example #3
0
        public async Task CloseGame(PokeTradeHubConfig config, CancellationToken token)
        {
            var timing = config.Timings;

            // Close out of the game
            await Click(HOME, 2_000 + timing.ExtraTimeReturnHome, token).ConfigureAwait(false);
            await Click(X, 1_000, token).ConfigureAwait(false);
            await Click(A, 5_000 + timing.ExtraTimeCloseGame, token).ConfigureAwait(false);

            Log("Closed out of the game!");
        }
Example #4
0
        public async Task StartGame(PokeTradeHubConfig config, CancellationToken token)
        {
            var timing = config.Timings;

            // Open game.
            await Click(A, 1_000 + timing.ExtraTimeLoadProfile, token).ConfigureAwait(false);

            // Menus here can go in the order: Update Prompt -> Profile -> DLC check -> Unable to use DLC.
            //  The user can optionally turn on the setting if they know of a breaking system update incoming.
            if (timing.AvoidSystemUpdate)
            {
                await Click(DUP, 0_600, token).ConfigureAwait(false);
                await Click(A, 1_000 + timing.ExtraTimeLoadProfile, token).ConfigureAwait(false);
            }

            await Click(A, 1_000 + timing.ExtraTimeCheckDLC, token).ConfigureAwait(false);

            // If they have DLC on the system and can't use it, requires an UP + A to start the game.
            // Should be harmless otherwise since they'll be in loading screen.
            await Click(DUP, 0_600, token).ConfigureAwait(false);
            await Click(A, 0_600, token).ConfigureAwait(false);

            Log("Restarting the game!");

            // Switch Logo lag, skip cutscene, game load screen
            await Task.Delay(10_000 + timing.ExtraTimeLoadGame, token).ConfigureAwait(false);

            for (int i = 0; i < 4; i++)
            {
                await Click(A, 1_000, token).ConfigureAwait(false);
            }

            var timer = 60_000;

            while (!await IsOnOverworld(config, token).ConfigureAwait(false) && !await IsInBattle(token).ConfigureAwait(false))
            {
                await Task.Delay(0_200, token).ConfigureAwait(false);

                timer -= 0_250;
                // We haven't made it back to overworld after a minute, so press A every 6 seconds hoping to restart the game.
                // Don't risk it if hub is set to avoid updates.
                if (timer <= 0 && !timing.AvoidSystemUpdate)
                {
                    Log("Still not in the game, initiating rescue protocol!");
                    while (!await IsOnOverworld(config, token).ConfigureAwait(false) && !await IsInBattle(token).ConfigureAwait(false))
                    {
                        await Click(A, 6_000, token).ConfigureAwait(false);
                    }
                    break;
                }
            }

            Log("Back in the overworld!");
        }
Example #5
0
        protected async Task EnterTradeCode(int code, PokeTradeHubConfig config, CancellationToken token)
        {
            var keys = TradeUtil.GetPresses(code);

            foreach (var key in keys)
            {
                int delay = config.Timings.KeypressTime;
                await Click(key, delay, token).ConfigureAwait(false);
            }
            // Confirm Code outside of this method (allow synchronization)
        }
Example #6
0
        protected virtual async Task EnterLinkCode(int code, PokeTradeHubConfig config, CancellationToken token)
        {
            // Default implementation to just press directional arrows. Can do via Hid keys, but users are slower than bots at even the default code entry.
            var keys = TradeUtil.GetPresses(code);

            foreach (var key in keys)
            {
                int delay = config.Timings.KeypressTime;
                await Click(key, delay, token).ConfigureAwait(false);
            }
            // Confirm Code outside of this method (allow synchronization)
        }
Example #7
0
        public async Task SaveGame(PokeTradeHubConfig config, CancellationToken token)
        {
            await Click(B, 0_200, token).ConfigureAwait(false);

            Log("Saving the game...");
            await Click(X, 2_000, token).ConfigureAwait(false);
            await Click(R, 0_250, token).ConfigureAwait(false);

            while (!await IsOnOverworld(config, token).ConfigureAwait(false))
            {
                await Click(A, 0_500, token).ConfigureAwait(false);
            }
            Log("Game saved!");
        }
Example #8
0
        public PokeTradeHub(PokeTradeHubConfig config)
        {
            Config = config;

            var giveawayPoolDatabase = new GiveawayPool(config);

            GiveawayPoolDatabase = giveawayPoolDatabase;


            BotSync = new BotSynchronizer(config.Distribution);
            BotSync.BarrierReleasingActions.Add(() => LogUtil.LogInfo($"{BotSync.Barrier.ParticipantCount} bots released.", "Barrier"));
            Counts = new BotCompleteCounts(config.Counts);

            Queues = new TradeQueueManager <T>(this);
        }
        public async Task <bool> IsOnOverworld(PokeTradeHubConfig config, CancellationToken token)
        {
            // Uses CurrentScreenOffset and compares the value to CurrentScreen_Overworld.
            if (config.ScreenDetection == ScreenDetectionMode.Original)
            {
                var data = await Connection.ReadBytesAsync(CurrentScreenOffset, 4, token).ConfigureAwait(false);

                return(BitConverter.ToUInt32(data, 0) == CurrentScreen_Overworld);
            }
            // Uses an appropriate OverworldOffset for the console language.
            else if (config.ScreenDetection == ScreenDetectionMode.ConsoleLanguageSpecific)
            {
                var data = await Connection.ReadBytesAsync(GetOverworldOffset(config.ConsoleLanguage), 1, token).ConfigureAwait(false);

                return(data[0] == 1);
            }
            return(false);
        }
Example #10
0
        public async Task StartGameSlow(PokeTradeHubConfig config, CancellationToken token)
        {
            // Open game and select profile.
            await Click(A, 2_000 + config.Timings.ExtraTimeLoadProfile, token).ConfigureAwait(false);
            await Click(A, 2_000 + config.Timings.ExtraTimeCheckDLC, token).ConfigureAwait(false);


            Log("Restarting the game!");

            // Switch Logo lag, skip cutscene, game load screen
            await Task.Delay(9_000 + config.Timings.ExtraTimeLoadGame, token).ConfigureAwait(false);

            while (!await IsOnOverworld(config, token).ConfigureAwait(false))
            {
                await Click(A, 2_000, token).ConfigureAwait(false);
            }

            Log("Back in the overworld!");
        }
Example #11
0
        public async Task ExitSeedCheckTrade(PokeTradeHubConfig config, CancellationToken token)
        {
            // Seed Check Bot doesn't show anything, so it can skip the first B press.
            int attempts = 0;

            while (!await IsOnOverworld(config, token).ConfigureAwait(false))
            {
                attempts++;
                if (attempts >= 15)
                {
                    break;
                }

                await Click(B, 1_000, token).ConfigureAwait(false);
                await Click(A, 1_000, token).ConfigureAwait(false);
            }

            await Task.Delay(3_000, token).ConfigureAwait(false);
        }
Example #12
0
        public async Task StartGame(PokeTradeHubConfig config, CancellationToken token, bool softReset = false)
        {
            // Open game.
            await Click(A, 1_000 + config.Timings.ExtraTimeLoadProfile, token).ConfigureAwait(false);

            // Menus here can go in the order: Update Prompt -> Profile -> DLC check -> Unable to use DLC.
            //  The user can optionally turn on the setting if they know of a breaking system update incoming.
            if (config.Timings.AvoidSystemUpdate)
            {
                await Click(DUP, 0_600, token).ConfigureAwait(false);
                await Click(A, 1_000 + config.Timings.ExtraTimeLoadProfile, token).ConfigureAwait(false);
            }

            await Click(A, 1_000 + config.Timings.ExtraTimeCheckDLC, token).ConfigureAwait(false);

            // If they have DLC on the system and can't use it, requires an UP + A to start the game.
            // Should be harmless otherwise since they'll be in loading screen.
            await Click(DUP, 0_600, token).ConfigureAwait(false);
            await Click(A, 0_600, token).ConfigureAwait(false);

            Log("Restarting the game!");

            // Switch Logo lag, skip cutscene, game load screen
            await Task.Delay(10_000 + config.Timings.ExtraTimeLoadGame, token).ConfigureAwait(false);

            for (int i = 0; i < 5; i++)
            {
                await Click(A, 1_000, token).ConfigureAwait(false);
            }

            while (!await IsOnOverworld(config, token).ConfigureAwait(false) && !softReset)
            {
                await Task.Delay(2_000, token).ConfigureAwait(false);
            }

            if (!softReset)
            {
                Log("Back in the overworld!");
            }
        }
        private static void InitializeTrainerDatabase(PokeTradeHubConfig cfg)
        {
            // Seed the Trainer Database with enough fake save files so that we return a generation sensitive format when needed.
            string OT   = cfg.GenerateOT;
            int    TID  = cfg.GenerateTID16;
            int    SID  = cfg.GenerateSID16;
            int    lang = (int)cfg.GenerateLanguage;

            var externalSource = cfg.GeneratePathTrainerInfo;

            if (!string.IsNullOrWhiteSpace(externalSource) && Directory.Exists(externalSource))
            {
                TrainerSettings.LoadTrainerDatabaseFromPath(externalSource);
            }

            SaveFile GetFallbackBlank(int generation)
            {
                var blankSav = SaveUtil.GetBlankSAV(generation, OT);

                blankSav.Language = lang;
                blankSav.TID      = TID;
                blankSav.SID      = SID;
                blankSav.OT       = OT;
                return(blankSav);
            }

            for (int i = 1; i < PKX.Generation + 1; i++)
            {
                var fallback = GetFallbackBlank(i);
                var exist    = TrainerSettings.GetSavedTrainerData(i, fallback);
                if (exist == fallback)
                {
                    TrainerSettings.Register(fallback);
                }
            }

            var trainer = TrainerSettings.GetSavedTrainerData(PKX.Generation);

            PKMConverter.SetPrimaryTrainer(trainer);
        }
Example #14
0
        public async Task ExitTrade(PokeTradeHubConfig config, bool unexpected, CancellationToken token)
        {
            if (unexpected)
            {
                Log("Unexpected behavior, recover position");
            }

            int attempts        = 0;
            int softBanAttempts = 0;

            while (!await IsOnOverworld(config, token).ConfigureAwait(false))
            {
                var screenID = await GetCurrentScreen(token).ConfigureAwait(false);

                if (screenID == CurrentScreen_Softban)
                {
                    softBanAttempts++;
                    if (softBanAttempts > 10)
                    {
                        await ReOpenGame(config, token).ConfigureAwait(false);
                    }
                }

                attempts++;
                if (attempts >= 15)
                {
                    break;
                }

                await Click(B, 1_000, token).ConfigureAwait(false);
                await Click(B, 1_000, token).ConfigureAwait(false);
                await Click(A, 1_000, token).ConfigureAwait(false);
            }

            if (config.Trade.SpinTrade)
            {
                await SpinCorrection(token).ConfigureAwait(false);
            }
        }
Example #15
0
        public async Task ReconnectToYComm(PokeTradeHubConfig config, CancellationToken token)
        {
            // Press B in case a Error Message is Present
            await Click(B, 2000, token).ConfigureAwait(false);

            // Return to Overworld
            if (!await IsOnOverworld(config, token).ConfigureAwait(false))
            {
                for (int i = 0; i < 5; i++)
                {
                    await Click(B, 500, token).ConfigureAwait(false);
                }
            }

            await Click(Y, 1000, token).ConfigureAwait(false);
            await Click(PLUS, 15_000, token).ConfigureAwait(false);

            for (int i = 0; i < 5; i++)
            {
                await Click(B, 500, token).ConfigureAwait(false);
            }
        }
 public GiveawayPool(PokeTradeHubConfig hub)
 {
     HubConfig = hub;
     CreateTable();
 }
 public BotCompleteCounts(PokeTradeHubConfig config)
 {
     Config = config;
     ReloadCounts();
 }
Example #18
0
 protected PokeBotRunner(PokeTradeHubConfig config, BotFactory <T> factory)
 {
     Factory = factory;
     Hub     = new PokeTradeHub <T>(config);
 }
Example #19
0
 public PokeBotRunnerImpl(PokeTradeHubConfig config, BotFactory <T> fac) : base(config, fac)
 {
 }
 public async Task ReOpenGame(PokeTradeHubConfig config, CancellationToken token)
 {
     Log("Error detected, restarting the game!!");
     await CloseGame(config, token).ConfigureAwait(false);
     await StartGame(config, token).ConfigureAwait(false);
 }
 private static void InitializeSettings(PokeTradeHubConfig cfg)
 {
     APILegality.SetAllLegalRibbons = cfg.SetAllLegalRibbons;
     APILegality.SetMatchingBalls   = cfg.SetMatchingBalls;
 }
Example #22
0
 public PokeBotRunnerImpl(PokeTradeHubConfig config) : base(config)
 {
 }
 public async Task ReOpenGame(PokeTradeHubConfig config, CancellationToken token)
 {
     await CloseGame(config, token).ConfigureAwait(false);
     await StartGame(config, token).ConfigureAwait(false);
 }
Example #24
0
 public PokemonPool(PokeTradeHubConfig settings)
 {
     Settings = settings;
 }
Example #25
0
 public BotEnvironmentImpl(PokeTradeHubConfig config) : base(config)
 {
 }
 public PokeTradeHub(PokeTradeHubConfig config)
 {
     Config = config;
     Counts = new BotCompleteCounts(config.Counts);
 }