Skip to content

Commit 88d97ff

Browse files
committed
Rewrite sys-botbase in C++, implement Pokémon Automation's tick-precise Computer-Control commands.
Project goals and major changes: - Make it easier to expand, modify, and work with. - Reduce heap, remove currently unused and ACNH commands. - Add logging to text file (always enabled for errors, exceptions. Optional toggle to enable all logging for debugging purposes). - Maintain current sys-botbase/usb-botbase compatibility (sans ACNH support), with an option to toggle backwards compatibility via command or in source if simplified CRLF/read/send is desired.
1 parent bb28f4a commit 88d97ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4540
-2548
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
.DS_Store
22
._*
33
build
4+
logs
5+
*.log
46
*.kip
57
*.elf
68
*.nso
79
*.nsp
8-
*.npdm
10+
*.npdm
11+
.git
12+
.vs

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

Makefile

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,145 @@
1-
.PHONY: all clean
1+
.SUFFIXES:
22

3-
all:
4-
@$(MAKE) -C sys-botbase/
3+
ifeq ($(strip $(DEVKITPRO)),)
4+
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
5+
endif
6+
7+
TOPDIR ?= $(CURDIR)
8+
include $(DEVKITPRO)/libnx/switch_rules
9+
10+
TARGET := sys-botbase
11+
BUILD := build
12+
SOURCES := source
13+
DATA := data
14+
INCLUDES := include
15+
EXEFS_SRC := exefs_src
16+
17+
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
18+
19+
CFLAGS := -g -Wall -O2 -ffunction-sections -fexceptions \
20+
$(ARCH) $(DEFINES)
21+
22+
CFLAGS += $(INCLUDE) -D__SWITCH__
23+
24+
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fexceptions -std=gnu++20
25+
26+
ASFLAGS := -g $(ARCH)
27+
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
28+
29+
LIBS := -lm -lnx
30+
31+
LIBDIRS := $(PORTLIBS) $(LIBNX)
32+
33+
ifneq ($(BUILD),$(notdir $(CURDIR)))
34+
35+
export OUTPUT := $(CURDIR)/$(TARGET)
36+
export TOPDIR := $(CURDIR)
37+
38+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
39+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
40+
41+
export DEPSDIR := $(CURDIR)/$(BUILD)
42+
43+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
44+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
45+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
46+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
47+
48+
ifeq ($(strip $(CPPFILES)),)
49+
export LD := $(CC)
50+
else
51+
export LD := $(CXX)
52+
endif
53+
54+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
55+
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
56+
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
57+
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
58+
59+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
60+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
61+
-I$(CURDIR)/$(BUILD)
62+
63+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
64+
65+
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
66+
67+
ifeq ($(strip $(CONFIG_JSON)),)
68+
jsons := $(wildcard *.json)
69+
ifneq (,$(findstring $(TARGET).json,$(jsons)))
70+
export APP_JSON := $(TOPDIR)/$(TARGET).json
71+
else
72+
ifneq (,$(findstring config.json,$(jsons)))
73+
export APP_JSON := $(TOPDIR)/config.json
74+
endif
75+
endif
76+
else
77+
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
78+
endif
79+
80+
.PHONY: $(BUILD) clean all
81+
.PHONY: all postbuild postbuildclean
82+
83+
all: $(BUILD)
84+
85+
$(BUILD):
86+
@[ -d $@ ] || mkdir -p $@
87+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
588

689
clean:
7-
@$(MAKE) clean -C sys-botbase/
90+
@echo clean ...
91+
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).npdm $(TARGET).nso $(TARGET).elf
92+
93+
#---------------------------------------------------------------------------------
94+
else
95+
.PHONY: all
96+
97+
DEPENDS := $(OFILES:.o=.d)
98+
99+
#---------------------------------------------------------------------------------
100+
# main targets
101+
#---------------------------------------------------------------------------------
102+
all : $(OUTPUT).nsp postbuild postbuildclean
103+
104+
ifeq ($(strip $(APP_JSON)),)
105+
$(OUTPUT).nsp : $(OUTPUT).nso
106+
else
107+
$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm
108+
endif
109+
110+
$(OUTPUT).nso : $(OUTPUT).elf
111+
112+
$(OUTPUT).elf : $(OFILES)
113+
114+
$(OFILES_SRC) : $(HFILES_BIN)
115+
116+
%.bin.o %_bin.h : %.bin
117+
@echo $(notdir $<)
118+
@$(bin2o)
119+
120+
-include $(DEPENDS)
121+
122+
postbuild: $(OUTPUT).nsp
123+
@echo "Running post-build steps..."
124+
@mkdir -p atmosphere/contents/430000000000000B/flags
125+
@cp $(OUTPUT).nsp atmosphere/contents/430000000000000B/exefs.nsp
126+
@echo wifi > atmosphere/contents/430000000000000B/config.cfg
127+
@touch atmosphere/contents/430000000000000B/flags/boot2.flag
128+
@powershell -Command "Compress-Archive -Path 'atmosphere' -DestinationPath 'atmosphere.zip' -Force"
129+
130+
@mkdir -p artifacts
131+
@cp $(OUTPUT).nsp artifacts
132+
@cp $(OUTPUT).elf artifacts
133+
@cp $(OUTPUT).nso artifacts
134+
@cp $(OUTPUT).npdm artifacts
135+
136+
postbuildclean: postbuild
137+
@echo "Running post-build clean steps..."
138+
rm -fr $(OUTPUT).nsp
139+
rm -fr $(OUTPUT).elf
140+
rm -fr $(OUTPUT).nso
141+
rm -fr $(OUTPUT).npdm
142+
rm -fr atmosphere
143+
rm -fr exefs
144+
145+
endif

README.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
# sys-botbase
2-
A Nintendo Switch (CFW) sys-module that allows users to remote control their switch via sockets as well as read and write to a games memory. This can be used to create bots for games and other fun automation projects.
1+
# sys-botbase-C++
2+
A Nintendo Switch (CFW) sys-module that allows users to remote control their Switch via local WiFi or USB, as well as read and write to a game's memory. This can be used to create bots for games and other fun automation projects.
3+
4+
This is a C++ rewrite of the original sys-botbase and usb-botbase with support for ACNH removed, tick-precise [Pokémon Automation's controller commands added](https://github.com/PokemonAutomation/ComputerControl), and reduced heap use.
5+
6+
It is designed to be backwards compatible with existing SysBot.NET implementations, though backwards compatibility can be disabled by sending `configure enableBackwardsCompat 0` or by setting `g_enableBackwardsCompat` in source and building the project.
7+
8+
With backwards compatibility disabled, WiFi and USB connections client-side can be simplified: read and send operations can be looped while there's data available, both connections send raw data (no decoding or endian conversion needed), both expect `\r\n` as a line terminator.
9+
10+
New structure should make the sys-module easier to maintain and extend, as well as make it easier to add new features.
311

412
## Features:
13+
### Tick-precise Controller Commands:
14+
- Send fast, asynchronous, tick-precise controller commands
15+
16+
Commands:
17+
- `cqControllerState {hex-encoded controller command struct}`: Set controller state. The command struct is a hex-encoded `ControllerCommand` struct. See `include/ControllerState.h` for details.
18+
- `cqReplaceOnNext`: Declare that the next command should atomically replace the entire command schedule.
19+
20+
This differs from `cqCancel + cqControllerState` in that the transition from the current schedule to the new command happens without returning the controller to the neutral state. Meaning if button `A` is being held down by the existing command schedule and is replaced with a new command that also holds `A`, the button `A` will be held throughout and never released.
21+
22+
Example usecase: SV sandwich making. If the current schedule is holding `A` to hold an ingredient and it needs to change directions, a `cqReplaceOnNext + new command` can be used to replace the path with the new path without ever releasing `A` as doing so will drop the ingredient.
23+
- `cqCancel`: Cancel all pending controller commands and set the controller state to neutral.
24+
525
### Remote Control:
626
- Set controller state
7-
- Simulate buttons press, hold, and release
27+
- Simulate button press, hold, and release
828
- Simulate touch screen drawing
29+
- Simulate keyboard input
930

1031
### Memory Reading and Writing:
1132
- Read/write x amount bytes of consecutive memory from RAM based on:
@@ -16,17 +37,30 @@ A Nintendo Switch (CFW) sys-module that allows users to remote control their swi
1637
### Screen Capture:
1738
- Capture current screen and return as JPG
1839

40+
### Logging:
41+
- Added text file logging to `atmosphere/contents/43000000000B/log.txt` for debugging purposes.
42+
- It will always log on error, exception, or during/after generally important operations. More verbose logging can be enabled by sending `configure enableLogs 1`.
43+
1944
## Disclaimer:
2045
This project was created for the purpose of development for bot automation. The creators and maintainers of this project are not liable for any damages caused or bans received. Use at your own risk.
2146

2247
## Installation
23-
Download [latest release](https://github.com/olliz0r/sys-botbase/releases/latest) and extract into your Nintendo Switch SD card. Restart your switch.
24-
25-
When installed correctly, sys-botbase will make your docked joy-con's home button glow on switch bootup. If this does not happen, sys-botbase is not installed correctly.
48+
1. Download [latest release](https://github.com/PokemonAutomation/sys-botbase-cpp/releases/latest) and extract into the root of your Nintendo Switch SD card.
49+
2. Open the `config.cfg` located in `atmosphere/contents/43000000000B` using your favorite text editor.
50+
3. Change text to `usb` if you want to connect using USB, or `wifi` if you want to connect using a local TCP connection. Defaults to `wifi`.
51+
4. Restart your Switch. If the right Joy-Con glows blue like shown, sys-botbase is installed correctly.
52+
![](joycon-glow.gif)
53+
5. Follow [SysBot's usb-botbase setup guide](https://github.com/kwsch/SysBot.NET/wiki/Configuring-a-new-USB-Connection) if you want to use USB.
2654

27-
![](joycon-glow.gif)
55+
## Building
56+
1. Clone this repository.
57+
2. Get [devkitPro](https://devkitpro.org/wiki/Getting_Started).
58+
3. Run `MSys2`, use `pacman -S switch-dev libnx switch-libjpeg-turbo devkitARM`. To easily update installed packages in the future, use `pacman -Syu`.
59+
4. Open the `.sln` with Visual Studio 2022 and build the solution. Alternatively, can run `MSys2`, `cd` to the cloned repository, and `make` (can optionally append ` -j$(nproc)`) to build the project.
2860

2961
## Credits
30-
- Big thank you to [jakibaki](https://github.com/jakibaki/sys-netcheat) for a great sysmodule base to learn and work with, as well as being helpful on the Reswitched discord!
31-
- Thanks to RTNX on discord for bringing to my attention a nasty little bug that would very randomly cause RAM poking to go bad and the switch (sometimes) crashing as a result.
62+
- Big thank you to [jakibaki](https://github.com/jakibaki/sys-netcheat) for a great sys-module base to learn and work with, as well as being helpful on the ReSwitched Discord!
63+
- Thanks to RTNX on Discord for bringing to my attention a nasty little bug that would very randomly cause RAM poking to go bad and the switch (sometimes) crashing as a result.
3264
- Thanks to Anubis for stress testing!
65+
- Thanks to FishGuy for the initial USB-Botbase implementation.
66+
- Thanks to Mysticial for the tick-precise controller input template, testing, and debugging.

0 commit comments

Comments
 (0)