-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
491 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "libs/libtesla"] | ||
path = libs/libtesla | ||
url = https://github.com/WerWolv/libtesla | ||
[submodule "libs/inih"] | ||
path = libs/inih | ||
url = https://github.com/benhoyt/inih.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Tesla-Template | ||
A template repository for Tesla Overlay Homebrews | ||
# fastCFWswitch | ||
A tesla based overlay to boot into different payloads on the Nintendo Switch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[CFWS] | ||
type=section | ||
name=cfws | ||
|
||
[ATMOSPHERE] | ||
name=atmosphere | ||
path=/atmosphere/reboot_payload.bin | ||
|
||
[SXOS] | ||
name=SxOS | ||
path=/sxos/reboot_payload.bin | ||
|
||
[TOOLS] | ||
name=Tools | ||
|
||
[HEKATE] | ||
name=Hekate | ||
path=/hekate_ctcaer_4.9.1.bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#include "configParser.h" | ||
#include "ini.h" | ||
#include <map> | ||
#include <list> | ||
#include <sstream> | ||
|
||
#include "section.h" | ||
#include "payload.h" | ||
|
||
using namespace fastCFWSwitcher; | ||
|
||
namespace fastCFWSwitcher { | ||
class ConfigEntry{ | ||
public: | ||
ConfigEntry(std::string section, int pos) : section(section), pos(pos){ | ||
this->type.assign("payload"); | ||
} | ||
void setType(const char * type){ | ||
this->type.assign(type); | ||
} | ||
void setName(const char * name){ | ||
this->name.assign(name); | ||
} | ||
void setPath(const char * path){ | ||
this->path.assign(path); | ||
} | ||
|
||
Element* toElement(){ | ||
if(type == "section" || path.empty()){ | ||
return (Element*) new Section(name); | ||
} else if(type == "payload"){ | ||
return (Element*) new Payload(name, path); | ||
} | ||
return nullptr; | ||
} | ||
|
||
static bool comparePos(const ConfigEntry* first, const ConfigEntry* second) | ||
{ | ||
return (first->pos < second->pos); | ||
} | ||
|
||
std::string section; | ||
int pos; | ||
std::string type; | ||
std::string name; | ||
std::string path; | ||
private: | ||
}; | ||
} | ||
|
||
int handler(void *user, const char *section, const char *name, const char *value) | ||
|
||
{ | ||
std::map<std::string, fastCFWSwitcher::ConfigEntry*>* elementsMap = (std::map<std::string, fastCFWSwitcher::ConfigEntry*>*) user; | ||
|
||
std::string sectionString(section); | ||
fastCFWSwitcher::ConfigEntry* configEntry ; | ||
|
||
std::map<std::string, fastCFWSwitcher::ConfigEntry*>::iterator it = elementsMap->find(sectionString); | ||
if( it != elementsMap->end() ){ | ||
configEntry = it->second; | ||
} else { | ||
configEntry = new fastCFWSwitcher::ConfigEntry(sectionString, elementsMap->size()); | ||
elementsMap->insert(std::pair<std::string, fastCFWSwitcher::ConfigEntry*>(sectionString, configEntry)); | ||
} | ||
|
||
if (!strcmp("type", name) ) { | ||
configEntry->setType(value); | ||
} else if (!strcmp("name", name) ) { | ||
configEntry->setName(value); | ||
} else if (!strcmp("path", name)) { | ||
configEntry->setPath(value); | ||
} | ||
return 1; | ||
} | ||
|
||
void ConfigParser::setError(std::string errorString){ | ||
this->list->addItem(new tsl::elm::CategoryHeader(errorString)); | ||
} | ||
|
||
std::list<Element*>* ConfigParser::getElements(){ | ||
|
||
// Read settings file | ||
|
||
FsFileSystem fsSdmc; | ||
|
||
if(R_FAILED(fsOpenSdCardFileSystem(&fsSdmc))){ | ||
setError("open sd failed\n"); | ||
return nullptr; | ||
} | ||
|
||
/* Open config file. */ | ||
FsFile fileConfig; | ||
if (R_FAILED(fsFsOpenFile(&fsSdmc, this->filePath, FsOpenMode_Read, &fileConfig))){ | ||
setError("open config file failed "); | ||
fsFsClose(&fsSdmc); | ||
return nullptr; | ||
} | ||
|
||
|
||
/* Get config file size. */ | ||
s64 configFileSize; | ||
if (R_FAILED(fsFileGetSize(&fileConfig, &configFileSize))){ | ||
setError("get file size failed\n"); | ||
fsFileClose(&fileConfig); | ||
fsFsClose(&fsSdmc); | ||
return nullptr; | ||
} | ||
|
||
std::vector<char> fileString(configFileSize+1); | ||
fileString[configFileSize] = 0; | ||
|
||
u64 readSize; | ||
Result rc = fsFileRead(&fileConfig, 0, &fileString[0], configFileSize, FsReadOption_None, &readSize); | ||
if (R_FAILED(rc) || readSize != static_cast<u64>(configFileSize)){ | ||
setError("read file failed\n"); | ||
fsFileClose(&fileConfig); | ||
fsFsClose(&fsSdmc); | ||
return nullptr; | ||
} | ||
|
||
fsFileClose(&fileConfig); | ||
fsFsClose(&fsSdmc); | ||
|
||
|
||
//parse ini file | ||
std::map<std::string, fastCFWSwitcher::ConfigEntry*> elementsMap; | ||
|
||
int config_err = ini_parse_string(&fileString[0], handler, &elementsMap); | ||
if(config_err<0){ | ||
setError("An error occured."); | ||
return nullptr; | ||
} else if(config_err>0){ | ||
std::stringstream ss; | ||
ss<< std::hex << config_err; // int decimal_value | ||
std::string res ( ss.str() ); | ||
setError("Bad config file, first error on line "+res); | ||
return nullptr; | ||
} | ||
std::list<fastCFWSwitcher::ConfigEntry*>* elementsList = new std::list<fastCFWSwitcher::ConfigEntry*>(); | ||
for (auto const& x : elementsMap) | ||
{ | ||
elementsList->push_back(x.second); | ||
} | ||
|
||
elementsList->sort(fastCFWSwitcher::ConfigEntry::comparePos); | ||
|
||
std::list<fastCFWSwitcher::Element*>* payloadList = new std::list<fastCFWSwitcher::Element*>(); | ||
|
||
for (fastCFWSwitcher::ConfigEntry* entry : *elementsList) | ||
{ | ||
fastCFWSwitcher::Element* element = entry->toElement(); | ||
if(element!=nullptr){ | ||
payloadList->push_back(element); | ||
//setError(x.second->path); | ||
} else { | ||
setError("error "+entry->section); | ||
} | ||
} | ||
return payloadList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
#include <tesla.hpp> | ||
#include "element.h" | ||
#include <list> | ||
|
||
#define CONFIG_FILE_PATH "/config/fastCFWSwitch/config.ini" | ||
|
||
namespace fastCFWSwitcher{ | ||
class ConfigParser{ | ||
public: | ||
ConfigParser(const char* filePath, tsl::elm::List* list) : filePath(filePath), list(list){ | ||
}; | ||
~ConfigParser(){ | ||
} | ||
std::list<fastCFWSwitcher::Element*>* getElements(); | ||
void setError(std::string errorString); | ||
|
||
private: | ||
const char* filePath; | ||
tsl::elm::List* list; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include <tesla.hpp> | ||
namespace fastCFWSwitcher{ | ||
class PayloadHandler; | ||
|
||
class Element{ | ||
public: | ||
virtual tsl::elm::ListItem* toListItem(fastCFWSwitcher::PayloadHandler* payloadHandler) = 0; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "payload.h" | ||
#include "payloadHandler.h" | ||
#include "element.h" | ||
|
||
using namespace fastCFWSwitcher; | ||
using namespace tsl::elm; | ||
|
||
|
||
|
||
|
||
ListItem* Payload::toListItem(PayloadHandler* payloadHandler){ | ||
auto item = new ListItem(this->name); | ||
std::function<bool(u64)> onClick = [item, payloadHandler, this](u64 keys) { | ||
if(keys & KEY_A){ | ||
item->setText("rebooting"); | ||
payloadHandler->rebootToPayload(this); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
item->setClickListener(onClick); | ||
return item; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include <tesla.hpp> | ||
#include "element.h" | ||
|
||
namespace fastCFWSwitcher { | ||
class Payload : Element { | ||
|
||
public: | ||
Payload(std::string name, std::string path) : name(name), path(path){ | ||
} | ||
~Payload(){}; | ||
tsl::elm::ListItem* toListItem(fastCFWSwitcher::PayloadHandler* payloadHandler); | ||
std::string getPath(){ | ||
return path; | ||
} | ||
|
||
private: | ||
std::string name; | ||
std::string path; | ||
}; | ||
} |
Oops, something went wrong.