Exemplo n.º 1
0
        public async Task <IReadOnlyCollection <VisitorDifference.Difference> > UpdateNames(CancellationToken token)
        {
            var formattedList = "The following visitors are on the island:\n";

            VisitorCount = 0;
            for (uint i = 0; i < VisitorListSize; ++i)
            {
                ulong offset = OffsetHelper.OnlineSessionVisitorAddress - (i * OffsetHelper.OnlineSessionVisitorSize);
                var   bytes  = await Connection.ReadBytesAsync((uint)offset, VisitorNameSize, token).ConfigureAwait(false);

                Visitors[i] = Encoding.UTF8.GetString(bytes).TrimEnd('\0');

                string VisitorInformation = "Available slot";
                if (!string.IsNullOrWhiteSpace(Visitors[i]))
                {
                    VisitorCount++;
                    VisitorInformation = Visitors[i];
                }

                formattedList += $"#{i + 1}: {VisitorInformation}\n";
            }

            VisitorFormattedString = formattedList;

            VisitorDifference currentVisitors = new VisitorDifference(Visitors);
            var toRet = LastVisitorDiff.GetDifferenceWith(currentVisitors);

            LastVisitorDiff = currentVisitors;
            return(toRet);
        }
        public async Task <(bool, byte[])> ReadValidateAsync(CancellationToken token)
        {
            var data = await Bot.ReadBytesAsync(DataOffset, size, token).ConfigureAwait(false);

            var validated = Validate(data);

            return(validated, data);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads an offset until it changes to either match or differ from the comparison value.
        /// </summary>
        /// <returns>If <see cref="match"/> is set to true, then the function returns true when the offset matches the given value.<br>Otherwise, it returns true when the offset no longer matches the given value.</br></returns>
        public async Task <bool> ReadUntilChanged(ulong offset, byte[] comparison, int waitms, int waitInterval, bool match, bool absolute, CancellationToken token)
        {
            var sw = new Stopwatch();

            sw.Start();
            do
            {
                var task = absolute
                    ? SwitchConnection.ReadBytesAbsoluteAsync(offset, comparison.Length, token)
                    : SwitchConnection.ReadBytesAsync((uint)offset, comparison.Length, token);
                var result = await task.ConfigureAwait(false);

                if (match == result.SequenceEqual(comparison))
                {
                    return(true);
                }

                await Task.Delay(waitInterval, token).ConfigureAwait(false);
            } while (sw.ElapsedMilliseconds < waitms);
            return(false);
        }
        public async Task GetDodoCode(ulong CoordinateAddress, uint Offset, bool isRetry, CancellationToken token)
        {
            // Navigate through dialog with Dodo to open gates and to get Dodo code.
            await Task.Delay(0_500, token).ConfigureAwait(false);

            var Hold = SwitchCommand.Hold(SwitchButton.L);
            await Connection.SendAsync(Hold, token).ConfigureAwait(false);

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

            await BotRunner.Click(SwitchButton.A, 4_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 2_000, token).ConfigureAwait(false);

            if (!isRetry)
            {
                await BotRunner.Click(SwitchButton.A, 2_100, token).ConfigureAwait(false);
            }
            await BotRunner.Click(SwitchButton.DDOWN, 0_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 2_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 1_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.DDOWN, 0_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 2_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 1_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 20_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 1_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.DUP, 0_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.DUP, 0_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 1_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 1_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.DUP, 0_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 2_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 1_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 1_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 2_500, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 3_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 2_000, token).ConfigureAwait(false);

            await BotRunner.Click(SwitchButton.A, 2_000, token).ConfigureAwait(false);

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

            var Release = SwitchCommand.Release(SwitchButton.L);
            await Connection.SendAsync(Release, token).ConfigureAwait(false);

            // Clear incase opening the gate took too long
            for (int i = 0; i < 6; ++i)
            {
                await BotRunner.Click(SwitchButton.B, 1_000, token).ConfigureAwait(false);
            }

            // Obtain Dodo code from offset and store it.
            byte[] bytes = await Connection.ReadBytesAsync(Offset, 0x5, token).ConfigureAwait(false);

            DodoCode = Encoding.UTF8.GetString(bytes, 0, 5);
            LogUtil.LogInfo($"Retrieved Dodo code: {DodoCode}.", Config.IP);

            // Wait for loading screen.
            while (await GetOverworldState(CoordinateAddress, token).ConfigureAwait(false) is not OverworldState.Overworld or OverworldState.Null)
            {
                await Task.Delay(0_500, token).ConfigureAwait(false);
            }
        }