Skip to content

About

CLI + C++20 lib for sys-botbase. Drive a Nintendo Switch over Wi-Fi: input, screenshots, memory r/w.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

78 Commits

Folders and files

Repository files navigation

botbase-cli

CI

A command line client (and C++20 library) for sys-botbase, the switch sysmodule that lets your computer press buttons, tap the screen, type, take screenshots and read/write game memory over wifi.

It supports every sys-botbase 2.6 command and works around most of the protocol's weird stuff. single binary, no dependencies.

$ botbase discover
192.168.1.50    sys-botbase 2.6
$ botbase info
version        2.6
charge         100
language       American English
title_id       01006A800016E000
build_id       21450c647b8c5940
...
$ botbase screenshot -o now.jpg
$ botbase click HOME
$ botbase type "Hello, world!" --enter
$ botbase peek 0x8 4 --region main --as hex

The old python version is on the legacy-python branch.

Install

Get a binary from releases. there's static linux builds (x86_64 and arm64) and a universal mac build for macOS 13.3+.

tar xzf botbase-*.tar.gz
sudo cp botbase-*/botbase /usr/local/bin/

The mac build isnt notarized so gatekeeper will block it the first time. run xattr -d com.apple.quarantine /usr/local/bin/botbase or just build it yourself.

Building

Needs CMake 3.20+ and a C++20 compiler (Apple Clang 15+, GCC 13+ or Clang 17+).

cmake -S . -B build
cmake --build build
ctest --test-dir build      # also runs the CLI tests if you have python3
cmake --install build       # optional

On the switch side you need atmosphere + sys-botbase. If you're on HOS 21 or newer read docs/server-setup.md first, the official v2.5 can crash the console at boot (2001-0132) and that page has the fix.

Usage

botbase [options] <command> [args...], and botbase help <command> for details on any of them. the main ones:

botbase discover --subnet 192.168.1.0/24
botbase info --json
botbase screenshot -o file.jpg            # -o - writes to stdout
botbase click A B --gap 200               # also press / release / hold A 1500
botbase stick left 0 32767 --ms 400
botbase seq A W500 DDOWN W200 +L %0,32767 W300 -L
botbase touch 640 360                     # touch-hold, touch-draw too
botbase type "text" --enter               # key Return, key-multi LeftShift A
botbase peek 0x40000 64 --region heap --as hex
botbase poke 0x40000 99 --as u32 --verify
botbase pointer 0x1c50c00 0x10 --final 0x8 --peek 4 --as u32
botbase freeze 0x40000 63                 # unfreeze, freezes count/clear/pause
botbase game name                         # game icon -o icon.jpg
botbase running 0x010000000000100D        # exit code 0 if running
botbase config mainLoopSleepTime 0
botbase home                              # close quits the game
botbase raw getTitleVersion               # or `shell` for a prompt

Useful global options: --fast drops mainLoopSleepTime to 0 for the run (roughly 2x faster, and it gets put back to 50 when it exits). --detach removes the virtual controller at the end so it doesnt keep holding a player slot. --timeout S changes the reply timeout (10s by default), -q hides status messages.

Finding the console

It uses --host first, then $BOTBASE_HOST. If neither is set it tries the last console it found (cached in ~/.cache/botbase/host) and only scans your /24 if that one doesn't answer anymore. If you have a VPN routing the same subnet as your LAN, --interface en0 (or $BOTBASE_INTERFACE) pins everything to one interface.

Scripts

batch runs a bunch of commands over one connection, from a file, stdin or -e. Split commands with newlines or ;, # for comments, wait MS to pause. It stops on the first error unless you pass --keep-going.

botbase batch <<'EOF'
home
wait 1000
touch 910 545    # System Settings
click A
wait 1500
screenshot -o settings.jpg
EOF

Why not just use netcat

sys-botbase takes plain text on TCP port 6000, one command per line (click A\r\n, peek 0x1000 0x10\r\n). Reads answer with a line of hex but writes dont answer at all, so you never know when something actually finished. botbase sends a getVersion after every write and waits for it, so when the command returns the console is actually done. It also keeps track of replies that are still in flight so a ctrl-c'd command doesn't leave a stray answer for the next one.

some other stuff it handles:

  • sys-botbase presses A for any button name it doesn't recognize (!). botbase checks names before sending anything, so a typo won't press A on you
  • ctrl-c during hold, stick --ms, seq or a touch lets go of the buttons, centers the sticks and exits with 130. failed scripts clean up the same way
  • When atmosphere's cheat engine is attached to the game (SaltyNX does this for any game with a cheats folder) memory reads fail silently. botbase tells you thats whats happening and how to fix it
  • type maps a US layout and sends capitals as shift chords, since the system keyboard ignores the shift modifier
  • clickSeq prints stray done lines that would mess up other replies, so they get filtered. seq runs steps client side by default because of an upstream strtok bug

It also refuses to turn on echoCommands and printDebugResultCodes since those add extra lines to every reply for every client. you can still set them through raw if you really want.

Exit codes: 0 ok, 1 general failure (or "no" from running/close/poke --verify), 2 bad args (nothing was sent), 3 couldn't connect, 4 timeout, 5 no game running, 6 another debugger has the game, 7 memory read failed, 130 interrupted.

Library

Link botbase::core and include <botbase/botbase.hpp>:

#include <botbase/botbase.hpp>

botbase::Client console({.host = "192.168.1.50", .interface = "en0"});

console.click("HOME");
console.type_text("Player 1");
botbase::Bytes jpeg = console.screenshot();

try {
    console.require_memory_access();
    botbase::Bytes hp = console.peek(0x40100, 4);
    console.poke(0x40100, {0xE7, 0x03, 0x00, 0x00});
} catch (const botbase::DebuggerBusy& error) {
    std::cerr << error.what() << '\n';  // explains the cheat engine conflict
}
console.detach_controller();

There's more in examples/ and include/botbase/client.hpp. docs/commands.md maps every wire command to its method and CLI command, and which ones have been tested on hardware.

Heads up

Port 6000 has no auth at all, anyone who can reach it can control your console and edit memory, so keep it on a network you trust. Writes happen immediately on the real console, and poking memory in an online game can get you banned. Settings are global and stay until you reboot. docs/quirks.md has every gotcha I ran into while testing.

Credits

olliz0r/sys-botbase and its contributors. The HOS 22 memory fix is PR #111 by quinnfrost.

Tested on an erista switch, HOS 22.5.0, Atmosphere 1.12.0, sys-botbase 2.6.

About

CLI + C++20 lib for sys-botbase. Drive a Nintendo Switch over Wi-Fi: input, screenshots, memory r/w.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages