Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# sys-botbase
# sys-botbase merged with usb-botbase

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.
A Nintendo Switch (CFW) sys-module that allows users to remote control their Switch via sockets or USB via a config file, 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.

## Features:

### Fork changes

- USB support based on [Koi-3088's](https://github.com/Koi-3088/usb-botbase) fork
- New command `dateSet {arg}`, where the argument `{arg}` is Unix Timestamp to be set.
- New command `resetTime`, `resetTimeNTP`, `getUnixTime` and `getCurrentTime`

Expand All @@ -31,10 +32,13 @@ A Nintendo Switch (CFW) sys-module that allows users to remote control their swi
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.

## Installation
1. Download [latest release](https://github.com/Eppin/sys-botbase/releases/latest) and extract into your Nintendo Switch SD card.
2. Open the `config.cfg` located in `atmosphere/contents/43000000000B` using your favorite text editor.
3. Set text to `wifi` if you want to connect wirelessly using sockets, or `usb` if you want to connect using a USB cable. Defaults to `wifi`.
4. Restart your Switch.
5. Follow [Sysbot.NET's usb-botbase setup guide](https://github.com/kwsch/SysBot.NET/wiki/Configuring-a-new-USB-Connection).

Download [latest release](https://github.com/Eppin/sys-botbase/releases/latest) and extract into your Nintendo Switch SD card. Restart your switch.

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.
When installed correctly, usb-botbase will make your docked joy-con's home button glow on switch bootup. If this does not happen, usb-botbase is not installed correctly.

![](joycon-glow.gif)

Expand All @@ -43,4 +47,5 @@ When installed correctly, sys-botbase will make your docked joy-con's home butto
- 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!
- 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.
- Thanks to Anubis for stress testing!
- And thanks to olliz0r!
- Thanks to FishGuy for the initial USB-Botbase implementation.
- And thanks to olliz0r and Koi-3088!
1 change: 1 addition & 0 deletions release/atmosphere/contents/430000000000000B/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wifi
2 changes: 1 addition & 1 deletion sys-botbase/source/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ int parseArgs(char *origargstr, int (*callback)(int, char **))
free(argv);
free(argstr);
return ret;
}
}
2 changes: 1 addition & 1 deletion sys-botbase/source/args.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int parseArgs(char* argstr, int (*callback)(int, char**));
int parseArgs(char* argstr, int (*callback)(int, char**));
124 changes: 77 additions & 47 deletions sys-botbase/source/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ HidDeviceType controllerInitializedType = HidDeviceType_FullKey3;
HiddbgHdlsHandle controllerHandle = {0};
HiddbgHdlsDeviceInfo controllerDevice = {0};
HiddbgHdlsState controllerState = {0};
USBResponse response;

time_t curTime = 0;
time_t origTime = 0;
Expand Down Expand Up @@ -90,7 +91,7 @@ u64 GetTitleVersion(u64 pid){
s32 out;

Result rc = nsInitialize();
if (R_FAILED(rc))
if (R_FAILED(rc))
fatalThrow(rc);

NsApplicationContentMetaStatus *MetaStatus = malloc(sizeof(NsApplicationContentMetaStatus[100U]));
Expand Down Expand Up @@ -170,20 +171,16 @@ void initController()
if(bControllerIsInitialised) return;
//taken from switchexamples github
Result rc = hiddbgInitialize();

//old
//if (R_FAILED(rc) && debugResultCodes)
//printf("hiddbgInitialize: %d\n", rc);

//new

if (R_FAILED(rc) && debugResultCodes) {
printf("hiddbgInitialize(): 0x%x\n", rc);
}
else {
workmem = aligned_alloc(0x1000, workmem_size);
if (workmem) initflag = 1;
if (workmem)
initflag = 1;
else printf("workmem alloc failed\n");
}
}

// Set the controller type to Pro-Controller, and set the npadInterfaceType.
controllerDevice.deviceType = controllerInitializedType;
Expand Down Expand Up @@ -225,7 +222,6 @@ void detachController()
hiddbgExit();
free(workmem);
bControllerIsInitialised = false;

sessionId.id = 0;
}

Expand All @@ -238,7 +234,7 @@ void poke(u64 offset, u64 size, u8* val)

void writeMem(u64 offset, u64 size, u8* val)
{
Result rc = svcWriteDebugProcessMemory(debughandle, val, offset, size);
Result rc = svcWriteDebugProcessMemory(debughandle, val, offset, size);
if (R_FAILED(rc) && debugResultCodes)
printf("svcWriteDebugProcessMemory: %d\n", rc);
}
Expand All @@ -250,38 +246,58 @@ void peek(u64 offset, u64 size)
readMem(out, offset, size);
detach();

u64 i;
for (i = 0; i < size; i++)
if (usb)
{
printf("%02X", out[i]);
response.size = size;
response.data = &out[0];
sendUsbResponse(response);
}
else
{
u64 i;
for (i = 0; i < size; i++)
printf("%02X", out[i]);
printf("\n");
}
printf("\n");
free(out);
}

void peekInfinite(u64 offset, u64 size)
{
u64 sizeRemainder = size;
u64 totalFetched = 0;
u64 i;
u8 *out = malloc(sizeof(u8) * MAX_LINE_LENGTH);
u8 *usbOut = malloc(size);

attach();
while (sizeRemainder > 0)
{
u64 thisBuffersize = sizeRemainder > MAX_LINE_LENGTH ? MAX_LINE_LENGTH : sizeRemainder;
sizeRemainder -= thisBuffersize;
readMem(out, offset + totalFetched, thisBuffersize);

u64 i;
for (i = 0; i < thisBuffersize; i++)
{
printf("%02X", out[i]);
if (usb)
usbOut[totalFetched + i] = out[i];
else printf("%02X", out[i]);
}

totalFetched += thisBuffersize;
}

detach();
printf("\n");
if (usb)
{
response.size = size;
response.data = &usbOut[0];
sendUsbResponse(response);
}
else printf("\n");

free(out);
free(usbOut);
}

void peekMulti(u64* offset, u64* size, u64 count)
Expand All @@ -300,18 +316,25 @@ void peekMulti(u64* offset, u64* size, u64 count)
}
detach();

u64 i;
for (i = 0; i < totalSize; i++)
if (usb)
{
response.size = totalSize;
response.data = &out[0];
sendUsbResponse(response);
}
else
{
printf("%02X", out[i]);
u64 i;
for (i = 0; i < totalSize; i++)
printf("%02X", out[i]);
printf("\n");
}
printf("\n");
free(out);
}

void readMem(u8* out, u64 offset, u64 size)
{
Result rc = svcReadDebugProcessMemory(out, debughandle, offset, size);
Result rc = svcReadDebugProcessMemory(out, debughandle, offset, size);
if (R_FAILED(rc) && debugResultCodes)
printf("svcReadDebugProcessMemory: %d\n", rc);
}
Expand Down Expand Up @@ -346,15 +369,15 @@ void setStickState(int side, int dxVal, int dyVal)
{
initController();
if (side == JOYSTICK_LEFT)
{
{
controllerState.analog_stick_l.x = dxVal;
controllerState.analog_stick_l.y = dyVal;
}
else
{
controllerState.analog_stick_r.x = dxVal;
controllerState.analog_stick_r.y = dyVal;
}
controllerState.analog_stick_l.y = dyVal;
}
else
{
controllerState.analog_stick_r.x = dxVal;
controllerState.analog_stick_r.y = dyVal;
}
hiddbgSetHdlsState(controllerHandle, &controllerState);
}

Expand All @@ -373,26 +396,26 @@ void reverseArray(u8* arr, int start, int end)

u64 followMainPointer(s64* jumps, size_t count)
{
u64 offset;
u64 offset;
u64 size = sizeof offset;
u8 *out = malloc(size);
MetaData meta = getMetaData();
attach();
readMem(out, meta.main_nso_base + jumps[0], size);
offset = *(u64*)out;
int i;
u8* out = malloc(size);
MetaData meta = getMetaData();
attach();
readMem(out, meta.main_nso_base + jumps[0], size);
offset = *(u64*)out;
int i;
for (i = 1; i < count; ++i)
{
readMem(out, offset + jumps[i], size);
offset = *(u64*)out;
{
readMem(out, offset + jumps[i], size);
offset = *(u64*)out;
// this traversal resulted in an error
if (offset == 0)
break;
}
detach();
free(out);
}
detach();
free(out);
return offset;
}

Expand Down Expand Up @@ -530,6 +553,13 @@ void clickSequence(char* seq, u8* token)
}
}

void sendUsbResponse(USBResponse response)
{
usbCommsWrite((void*)&response, 4);
if (response.size > 0)
usbCommsWrite(response.data, response.size);
}

void dateSet(uint64_t date)
{
Result ts = timeSetCurrentTime(TimeType_NetworkSystemClock, date);
Expand Down Expand Up @@ -596,4 +626,4 @@ long getCurrentTime()
return -1;
}
return curTime;
}
}
14 changes: 12 additions & 2 deletions sys-botbase/source/commands.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <switch.h>
#include <time.h>
#define TOUCHPOLLMIN 15000000L // touch screen polling rate seems to be 15ms (no idea how to change)

extern Handle debughandle;
extern bool bControllerIsInitialised;
Expand All @@ -12,6 +13,9 @@ extern u64 buttonClickSleepTime;
extern u64 keyPressSleepTime;
extern u64 pollRate;
extern u32 fingerDiameter;
extern bool usb;
extern u8* hdlmem;
extern size_t hdlmem_size;

typedef struct {
u64 main_nso_base;
Expand All @@ -35,6 +39,12 @@ typedef struct {
u8 state;
} KeyData;

typedef struct
{
u64 size;
void* data;
}USBResponse;

#define JOYSTICK_LEFT 0
#define JOYSTICK_RIGHT 1

Expand Down Expand Up @@ -65,9 +75,9 @@ u64 followMainPointer(s64* jumps, size_t count);
void touch(HidTouchState* state, u64 sequentialCount, u64 holdTime, bool hold, u8* token);
void key(HiddbgKeyboardAutoPilotState* states, u64 sequentialCount);
void clickSequence(char* seq, u8* token);

void sendUsbResponse(USBResponse response);
void dateSet(uint64_t date);
void resetTime();
void resetTimeNTP();
long getUnixTime();
long getCurrentTime();
long getCurrentTime();
2 changes: 1 addition & 1 deletion sys-botbase/source/freeze.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ u8 clearFreezes(void)
}
}
return clearedOne;
}
}
2 changes: 1 addition & 1 deletion sys-botbase/source/freeze.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ int findNextEmptySlot();
int addToFreezeMap(u64 addr, u8* v_data, u64 v_size, u64 tid);
int removeFromFreezeMap(u64 addr);
int getFreezeCount(bool print);
u8 clearFreezes(void);
u8 clearFreezes(void);
Loading