public byte[] ReadBytesUSB(uint offset, int length)
        {
            if (length > MaximumTransferSize)
            {
                return(ReadBytesLarge(offset, length));
            }
            lock (_sync)
            {
                var cmd = SwitchCommand.PeekUSB(offset, length);
                SendInternal(cmd);
                Thread.Sleep(1);

                var buffer = new byte[length];
                var _      = ReadInternal(buffer);
                return(buffer);
            }
        }
        public void DisconnectUSB()
        {
            lock (_sync)
            {
                if (SwDevice != null)
                {
                    SendUSB(SwitchCommand.DetachController());
                    if (SwDevice.IsOpen)
                    {
                        if (SwDevice is IUsbDevice wholeUsbDevice)
                        {
                            wholeUsbDevice.ReleaseInterface(0);
                        }
                        SwDevice.Close();
                    }
                }

                reader?.Dispose();
                writer?.Dispose();
            }
        }
        public async Task BootLanMode(int hold, CancellationToken token)
        {
            // Set hold delay
            var delaycgf = SwitchCommand.Configure(SwitchConfigureParameter.buttonClickSleepTime, hold);
            await Connection.SendAsync(delaycgf, token).ConfigureAwait(false);

            // Hold the buttons
            await Connection.SendAsync(SwitchCommand.Hold(SwitchButton.L), token).ConfigureAwait(false);

            await Connection.SendAsync(SwitchCommand.Hold(SwitchButton.R), token).ConfigureAwait(false);

            await Connection.SendAsync(SwitchCommand.Hold(SwitchButton.LSTICK), token).ConfigureAwait(false);

            // Reset delay
            delaycgf = SwitchCommand.Configure(SwitchConfigureParameter.buttonClickSleepTime, 50); // 50 ms
            await Connection.SendAsync(delaycgf, token).ConfigureAwait(false);

            // Release the buttons
            await Connection.SendAsync(SwitchCommand.Release(SwitchButton.L), token).ConfigureAwait(false);

            await Connection.SendAsync(SwitchCommand.Release(SwitchButton.R), token).ConfigureAwait(false);

            await Connection.SendAsync(SwitchCommand.Release(SwitchButton.LSTICK), token).ConfigureAwait(false);
        }
        public async Task Click(SwitchButton b, int delay, CancellationToken token)
        {
            await Connection.SendAsync(SwitchCommand.Click(b), Config.ConnectionType, token).ConfigureAwait(false);

            await Task.Delay(delay, token).ConfigureAwait(false);
        }
 public async Task EchoCommands(bool value, CancellationToken token)
 {
     var cmd = SwitchCommand.Configure(SwitchConfigureParameter.echoCommands, value ? 1 : 0);
     await Connection.SendAsync(cmd, Config.ConnectionType, token).ConfigureAwait(false);
 }
 public async Task DetachController(CancellationToken token)
 {
     await Connection.SendAsync(SwitchCommand.DetachController(), Config.ConnectionType, token).ConfigureAwait(false);
 }
 public async Task SetScreen(bool on, CancellationToken token)
 {
     await Connection.SendAsync(SwitchCommand.SetScreen(on, UseCRLF), token).ConfigureAwait(false);
 }
        public async Task WriteBytesAbsoluteAsync(byte[] data, ulong offset, CancellationToken token)
        {
            var cmd = SwitchCommand.PokeAbsolute(offset, data);

            await SendAsync(cmd, token).ConfigureAwait(false);
        }
 public Task PointerPoke(byte[] data, IEnumerable <long> jumps, CancellationToken token)
 {
     return(Task.Run(() => Send(SwitchCommand.PointerPoke(jumps, data, false)), token));
 }
 public async Task <byte[]> ReadBytesMainAsync(ulong offset, int length, CancellationToken token)
 {
     return(await ReadBytesFromCmdAsync(SwitchCommand.PeekMain(offset, length), length, token).ConfigureAwait(false));
 }
 public async Task ResetTime(CancellationToken token) => await Connection.SendAsync(SwitchCommand.ResetTime(UseCRLF), token).ConfigureAwait(false);
 public async Task DaySkip(CancellationToken token) => await Connection.SendAsync(SwitchCommand.DaySkip(UseCRLF), token).ConfigureAwait(false);
Exemple #13
0
 public ulong GetHeapBase()
 {
     Send(SwitchCommand.GetHeapBase(false));
     byte[] baseBytes = ReadBulkUSB();
     return(BitConverter.ToUInt64(baseBytes, 0));
 }
Exemple #14
0
 public ulong GetMainNsoBase()
 {
     Send(SwitchCommand.GetMainNsoBase(false));
     byte[] baseBytes = ReadResponse(8);
     return(BitConverter.ToUInt64(baseBytes, 0));
 }
Exemple #15
0
 public async Task DaySkip(int resetAfterNSkips, int resetNTP, CancellationToken token) => await Connection.SendAsync(SwitchCommand.DaySkip(resetAfterNSkips, resetNTP, UseCRLF), token).ConfigureAwait(false);