Skip to content

Commit

Permalink
added checking for hekate before applying hekate style payload params
Browse files Browse the repository at this point in the history
improved the readme
updated to the latest libtesla
  • Loading branch information
Hartie95 committed May 31, 2020
1 parent dbbe01a commit ab3e990
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 20 deletions.
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
# fastCFWswitch
A tesla based overlay to boot into different payloads on the Nintendo Switch.
A tesla based overlay to boot into different payloads on the Nintendo Switch.

## Setup
* Setup the [tesla menu](https://github.com/WerWolv/Tesla-Menu) and [nx-ovlloader](https://github.com/WerWolv/ovl-sysmodules)
* Extract the [latest release](https://github.com/Hartie95/fastCFWswitch/releases/latest) to the sd card
* Modify the configuration in `/config/fastCFWSwitch/config.ini`

## Configuration

Attribute | possible values | Description
----------- | ------------------------------------------ | ----------------
`type` | empty / `section` / `payload` | This defines the type of element this section defines, if left empty it will automatically differentiate it by checking if a path is set
`name` | any string - example: `atmosphere` | The entry name, shown in the Overlay
`path` | a path - example: `/bootloader/hekate.bin` | the absolute path, based on the root of the sd, to the payload that should be loaded
`bootPos` | a number | the config position of the config the target payload should load, currently only supported for hekate
`bootId` | an 1-7 character long string - example `atmos` | the id of the config entry the target should be loaded, supported for hekate 5.0.2+

## Example configuration
```
[CFWS]
type=section
name=cfws
[SYSNAND]
name=sysnand
path=/payloads/hekate_ctcaer.bin
bootId=sysnand
[EMUNAND]
name=emunand
path=/payloads/hekate_ctcaer.bin
bootId=emunand
[ATMOSPHERE]
name=atmosphere
path=/atmosphere/reboot_payload.bin
[SXOS]
name=SxOS
path=/sxos/reboot_payload.bin
[ANDROID]
name=Android
path=/payloads/hekate_ctcaer.bin
bootPos=2
[TOOLS]
name=Tools
[HEKATE]
name=Hekate
path=/payloads/hekate_ctcaer.bin
[LOCKPICKRCM]
name=Hekate
path=/payloads/Lockpick_RCM.bin
```

## Screenshots
![Example Menu](../master/media/exampleMenu.jpg?raw=true)


## Credits
* [libtestla](https://github.com/WerWolv/libtesla) by [WerWolv](https://github.com/WerWolv) as base for this overlay
* [libnx](https://github.com/switchbrew/libnx) as base of almost all switch homebrew
* [inih](https://github.com/benhoyt/inih) for the ini parsing lib
2 changes: 1 addition & 1 deletion libs/libtesla
Binary file added media/exampleMenu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion out/config/fastCFWSwitch/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
type=section
name=cfws

[EMUNAND]
name=emunand
path=/payloads/hekate_ctcaer.bin
bootId=emunand

[SYSNAND]
name=sysnand
path=/payloads/hekate_ctcaer.bin
bootId=sysnand

[ATMOSPHERE]
name=atmosphere
path=/atmosphere/reboot_payload.bin
Expand All @@ -10,9 +20,18 @@ path=/atmosphere/reboot_payload.bin
name=SxOS
path=/sxos/reboot_payload.bin

[ANDROID]
name=Android
path=/payloads/hekate_ctcaer.bin
bootPos=2

[TOOLS]
name=Tools

[HEKATE]
name=Hekate
path=/hekate_ctcaer_4.9.1.bin
path=/payloads/hekate_ctcaer.bin

[LOCKPICKRCM]
name=Hekate
path=/payloads/Lockpick_RCM.bin
2 changes: 1 addition & 1 deletion source/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace fastCFWSwitcher{

class Element{
public:
virtual tsl::elm::ListItem* toListItem(fastCFWSwitcher::PayloadHandler* payloadHandler) = 0;
virtual tsl::elm::Element* toListItem(fastCFWSwitcher::PayloadHandler* payloadHandler) = 0;
};
}
2 changes: 1 addition & 1 deletion source/payload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace tsl::elm;



ListItem* Payload::toListItem(PayloadHandler* payloadHandler){
tsl::elm::Element* Payload::toListItem(PayloadHandler* payloadHandler){
auto item = new ListItem(this->name);
std::function<bool(u64)> onClick = [item, payloadHandler, this](u64 keys) {
if(keys & KEY_A){
Expand Down
2 changes: 1 addition & 1 deletion source/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace fastCFWSwitcher {
Payload(std::string name, std::string path) : name(name), path(path){
}
~Payload(){};
tsl::elm::ListItem* toListItem(fastCFWSwitcher::PayloadHandler* payloadHandler);
tsl::elm::Element* toListItem(fastCFWSwitcher::PayloadHandler* payloadHandler);
std::string getPath(){
return path;
}
Expand Down
47 changes: 35 additions & 12 deletions source/payloadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ alignas(0x1000) static u8 g_work_page[0x1000];
alignas(0x1000) static u8 g_reboot_payload[IRAM_PAYLOAD_MAX_SIZE];


//Hekate config and magic
#define HEKATE_AUTOBOOT_POS 0x94
#define HEKATE_MAGIC_POS 0x118
#define HEKATE_VERSION 0x11C
#define HEKATE_MAGIC 0x43544349

#define BOOT_CFG_AUTOBOOT_EN (1 << 0)
#define BOOT_CFG_FROM_LAUNCH (1 << 1)
#define BOOT_CFG_FROM_ID (1 << 2)
#define BOOT_CFG_TO_EMUMMC (1 << 3)
#define BOOT_CFG_SEPT_RUN (1 << 7)


typedef struct __attribute__((__packed__)) _boot_cfg_t
{
u8 boot_cfg;
Expand Down Expand Up @@ -76,21 +81,39 @@ void PayloadHandler::setError(std::string errorString){
}

void PayloadHandler::applyPayloadArgs(fastCFWSwitcher::Payload* payload){
if(!payload->getBootId().empty()){
boot_cfg_t* hekateCFG = (boot_cfg_t*) &g_reboot_payload[HEKATE_AUTOBOOT_POS];
hekateCFG->boot_cfg = BOOT_CFG_FROM_ID|BOOT_CFG_AUTOBOOT_EN;

std::string bootID = payload->getBootId();
strcpy(hekateCFG->id, bootID.c_str());

} else if (payload->getBootPos()!=-1){
boot_cfg_t* hekateCFG = (boot_cfg_t*) &g_reboot_payload[HEKATE_AUTOBOOT_POS];
hekateCFG->boot_cfg = BOOT_CFG_AUTOBOOT_EN;
hekateCFG->autoboot = payload->getBootPos();
hekateCFG->autoboot_list = 0;
PayloadType payloadType = getBinPayloadType(payload);

switch(payloadType){
case PayloadType::HEKATE:
int hekateVersion = strtol((char*)&g_reboot_payload[HEKATE_VERSION], (char **)NULL, 10);
if(hekateVersion>=502 && !payload->getBootId().empty()){
boot_cfg_t* hekateCFG = (boot_cfg_t*) &g_reboot_payload[HEKATE_AUTOBOOT_POS];
hekateCFG->boot_cfg = BOOT_CFG_FROM_ID|BOOT_CFG_AUTOBOOT_EN;

std::string bootID = payload->getBootId();
strcpy(hekateCFG->id, bootID.c_str());

} else if (payload->getBootPos()!=-1){
boot_cfg_t* hekateCFG = (boot_cfg_t*) &g_reboot_payload[HEKATE_AUTOBOOT_POS];
hekateCFG->boot_cfg = BOOT_CFG_AUTOBOOT_EN;
hekateCFG->autoboot = payload->getBootPos();
hekateCFG->autoboot_list = 0;
}
}
}


PayloadType PayloadHandler::getBinPayloadType(fastCFWSwitcher::Payload* payload){

u32 hekateMagic=*((u32*)&g_reboot_payload[HEKATE_MAGIC_POS]);
if(hekateMagic==HEKATE_MAGIC){
return PayloadType::HEKATE;

}
return PayloadType::UNKOWN;
}


bool PayloadHandler::loadPayload(fastCFWSwitcher::Payload* payload){
FsFileSystem fsSdmc;
FsFile fileConfig;
Expand Down
6 changes: 6 additions & 0 deletions source/payloadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace fastCFWSwitcher {

enum class PayloadType {
UNKOWN = 1,
HEKATE = 2
};

class PayloadHandler{

public:
Expand All @@ -20,6 +25,7 @@ namespace fastCFWSwitcher {
void clear_iram(void);
bool loadPayload(fastCFWSwitcher::Payload* payload);
void applyPayloadArgs(fastCFWSwitcher::Payload* payload);
PayloadType getBinPayloadType(fastCFWSwitcher::Payload* payload);
tsl::elm::OverlayFrame* frame;
};
}
2 changes: 1 addition & 1 deletion source/section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
using namespace fastCFWSwitcher;
using namespace tsl::elm;

ListItem* Section::toListItem(fastCFWSwitcher::PayloadHandler* PayloadHandler){
tsl::elm::Element* Section::toListItem(fastCFWSwitcher::PayloadHandler* PayloadHandler){
return new CategoryHeader(this->name);
}
2 changes: 1 addition & 1 deletion source/section.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace fastCFWSwitcher {
Section(std::string name) : name(name){
}
~Section(){}
tsl::elm::ListItem* toListItem(fastCFWSwitcher::PayloadHandler* PayloadHandler);
tsl::elm::Element* toListItem(fastCFWSwitcher::PayloadHandler* PayloadHandler);

private:
std::string name;
Expand Down

0 comments on commit ab3e990

Please sign in to comment.