Skip to content

Commit

Permalink
Added GUI option to disable cheat updates
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletDuFromage committed Sep 26, 2020
1 parent cce7d21 commit 42ac921
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DATA := data
INCLUDES := include lib/zipper/include
APP_TITLE := All-in-One Switch Updater
APP_AUTHOR := HamletDuFromage
APP_VERSION := 1.1.1
APP_VERSION := 1.1.2

#ROMFS := $(BUILD)/romfs
BOREALIS_PATH := lib/borealis
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# AIO-switch-updater
![releases](https://img.shields.io/github/downloads/HamletDuFromage/AIO-switch-updater/total)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/HamletDuFromage/AIO-switch-updater/Build%20AIO-switch-updater)
![tag](https://img.shields.io/github/v/release/HamletDuFromage/AIO-switch-updater)
![GitHub](https://img.shields.io/github/license/HamletDuFromage/aio-switch-updater)

Expand Down Expand Up @@ -27,7 +28,7 @@ For Atmosphere. Downloads sigpatches, which are patches required for launching u
Download firmare files to `/firmware` that can then be installed using DayBreak or ChoiDuJour.

### ⬦ Download cheats
Downloads and extracts daily-updated cheat code. The program will only extract cheat codes for the games you own. By default, this homebrew will overwrite the existing cheats. If you have your own cheat files that you'd like to keep as is, you may add the title IDs of the corresponding games, one ID per line, to `/config/cheats-updater/exclude.txt`. Use http://tinfoil.io/title to find the title ID of a game.
Downloads and extracts daily-updated cheat code. The program will only extract cheat codes for the games you own. By default, this homebrew will overwrite the existing cheats. If you have your own cheat files that you'd like to keep as is, you can turn off cheat updates for specific titles in `Tools->Cheat Menu`.

## Extras (in the `Tools` tab)
- Reboot to specific payload.
Expand Down
13 changes: 1 addition & 12 deletions include/app_page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@
#include "worker_page.hpp"
#include "confirm_page.hpp"

#define PROFILE_BADGE "\uE3E0"
typedef struct app App;

typedef char NsApplicationName[0x201];
typedef uint8_t NsApplicationIcon[0x20000];

typedef struct
{
uint64_t tid;
NsApplicationName name;
NsApplicationIcon icon;

brls::ListItem* listItem;
} App;

class AppPage : public brls::AppletFrame
{
Expand Down
18 changes: 18 additions & 0 deletions include/cheats_page.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <borealis.hpp>
#include "app_page.hpp"
#include "exclude_page.hpp"

class CheatsPage : public brls::AppletFrame
{
private:
brls::List* list;
brls::ListItem* view;
brls::ListItem* deleteCheats;
brls::ListItem* exclude;
brls::StagedAppletFrame* stagedFrame;

public:
CheatsPage();
};
30 changes: 30 additions & 0 deletions include/exclude_page.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <borealis.hpp>
#include <switch.h>
#include <cstring>
#include "utils.hpp"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>

typedef struct app App;

class ExcludePage : public brls::AppletFrame
{
private:
brls::List* list;
brls::Label* label;
brls::ListItem* save;
std::vector<App*> apps;
std::set<std::string> titles;
//std::vector<brls::ToggleListItem*> items;
std::tuple<std::vector<brls::ToggleListItem*>, std::vector<std::string>> items;

public:
ExcludePage();
};
2 changes: 1 addition & 1 deletion include/extract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ void extract(const char * filename, const char* workingPath, const char* toExclu
std::string formatApplicationId(u64 ApplicationId);
std::vector<Title> getInstalledTitlesNs();
std::vector<Title> excludeTitles(const char* path, std::vector<Title> listedTitles);
void writeTitlesToFile(std::set<std::string> titles);
void writeTitlesToFile(std::set<std::string> titles, const char* path);
void extractCheats(const char * zipPath, std::vector<Title> titles, CFW cfw, bool credits = false);
void removeCheats(CFW cfw);
7 changes: 3 additions & 4 deletions include/tools_tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <borealis.hpp>
#include "confirm_page.hpp"
#include "worker_page.hpp"
#include "app_page.hpp"
#include "cheats_page.hpp"
#include "payload_page.hpp"
#include "download_payload_page.hpp"
#include "changelog_page.hpp"
Expand All @@ -14,12 +14,11 @@
class ToolsTab : public brls::List
{
private:
brls::ListItem* deleteCheats;
brls::ListItem* viewCheats;
brls::ListItem* cheats;
brls::ListItem* JCcolor;
brls::ListItem* updateApp;
brls::ListItem* rebootPayload;
brls::ListItem* downloadPaysload;
brls::ListItem* downloadPayload;
brls::ListItem* changelog;
brls::StagedAppletFrame* stagedFrame;

Expand Down
13 changes: 13 additions & 0 deletions include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
#include <regex>
#include <iostream>
#include <set>
#include <switch.h>
#include "download.hpp"
#include "extract.hpp"
#include "constants.hpp"
#include "progress_event.hpp"
#include "json.hpp"
#include "main_frame.hpp"

typedef char NsApplicationName[0x201];
typedef uint8_t NsApplicationIcon[0x20000];

struct app
{
uint64_t tid;
NsApplicationName name;
NsApplicationIcon icon;

brls::ListItem* listItem;
};

CFW getCFW();
bool isServiceRunning(const char *serviceName);
std::vector<std::string> htmlProcess(std::string s, std::regex rgx);
Expand Down
1 change: 0 additions & 1 deletion source/app_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,4 @@ AppPage::AppPage() : AppletFrame(true, true)
});
list->addView(download);
this->setContentView(list);

}
3 changes: 3 additions & 0 deletions source/changelog_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ChangelogPage::ChangelogPage() : AppletFrame(true, true)
"\uE016 Added the possibility to copy a payload to '/atmosphere/reboot_payload.bin'\n"\
"\uE016 Added changelog in 'Tools'\n");

verTitles.push_back("v1.1.2");
changes.push_back("\uE016 Added GUI to disable cheat updates for specific titles.");

int nbVersions = verTitles.size();
items.reserve(nbVersions);
for(int i = nbVersions -1 ; i >= 0; i--){
Expand Down
36 changes: 36 additions & 0 deletions source/cheats_page.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "cheats_page.hpp"

CheatsPage::CheatsPage() : AppletFrame(true, true)
{
this->setTitle("Cheats menu");
list = new brls::List();

view = new brls::ListItem("View installed cheats");
view->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new AppPage());
});
list->addView(view);

exclude = new brls::ListItem("Exclude games from recieving cheat updates");
exclude->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new ExcludePage());
});
list->addView(exclude);


deleteCheats = new brls::ListItem("Delete all existing cheat codes");
deleteCheats->getClickEvent()->subscribe([&](brls::View* view){
stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle("Delete all cheats");
stagedFrame->addStage(
new WorkerPage(stagedFrame, "Deleting", [](){removeCheats(getCFW());})
);
stagedFrame->addStage(
new ConfirmPage(stagedFrame, "All done!", true)
);
brls::Application::pushView(stagedFrame);
});
list->addView(deleteCheats);

this->setContentView(list);
}
80 changes: 80 additions & 0 deletions source/exclude_page.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "exclude_page.hpp"

ExcludePage::ExcludePage() : AppletFrame(true, true)
{
this->setTitle("Exclude titles");
list = new brls::List();
label = new brls::Label(
brls::LabelStyle::DESCRIPTION,
"You can turn off cheat updates with this menu",
true
);
list->addView(label);

NsApplicationRecord record;
uint64_t tid;
NsApplicationControlData controlData;
NacpLanguageEntry* langEntry = NULL;

Result rc;
size_t i = 0;
int recordCount = 0;
size_t controlSize = 0;

titles = readLineByLine(CHEATS_EXCLUDE);

//std::tuple<std::vector<brls::ToggleListItem*>, std::vector<std::string>> items;

while (true)
{
rc = nsListApplicationRecord(&record, sizeof(record), i, &recordCount);
if (R_FAILED(rc)) break;

if(recordCount <= 0)
break;

tid = record.application_id;
rc = nsGetApplicationControlData(NsApplicationControlSource_Storage, tid, &controlData, sizeof(controlData), &controlSize);
if (R_FAILED(rc)) break;
rc = nacpGetLanguageEntry(&controlData.nacp, &langEntry);
if (R_FAILED(rc)) break;
if (!langEntry->name)
{
i++;
continue;
}
App* app = (App*) malloc(sizeof(App));
app->tid = tid;

memset(app->name, 0, sizeof(app->name));
strncpy(app->name, langEntry->name, sizeof(app->name)-1);

memcpy(app->icon, controlData.icon, sizeof(app->icon));

// Add the ListItem
brls::ToggleListItem *listItem;
if(titles.find(formatApplicationId(tid)) != titles.end())
listItem = new brls::ToggleListItem(formatListItemTitle(std::string(app->name)), 0);
else
listItem = new brls::ToggleListItem(formatListItemTitle(std::string(app->name)), 1);

listItem->setThumbnail(app->icon, sizeof(app->icon));
std::get<0>(items).push_back(listItem);
std::get<1>(items).push_back(formatApplicationId(app->tid));
list->addView(listItem);
i++;
}

list->registerAction("Save choice and return", brls::Key::B, [this] {
std::set<std::string> exclude{};
for(int i = 0; i < (int) std::get<1>(items).size(); i++){
if(!std::get<0>(items)[i]->getToggleState()){
exclude.insert(std::get<1>(items)[i]);
}
}
writeTitlesToFile(exclude, CHEATS_EXCLUDE);
brls::Application::popView();
return true;
});
this->setContentView(list);
}
6 changes: 3 additions & 3 deletions source/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ void extractCheats(const char * zipPath, std::vector<Title> titles, CFW cfw, boo
}
}
unzipper.close();
writeTitlesToFile(extractedTitles);
writeTitlesToFile(extractedTitles, UPDATED_TITLES_PATH);
ProgressEvent::instance().setStep(ProgressEvent::instance().getMax());
}

void writeTitlesToFile(std::set<std::string> titles){
void writeTitlesToFile(std::set<std::string> titles, const char* path){
std::ofstream updatedTitlesFile;
std::set<std::string>::iterator it = titles.begin();
updatedTitlesFile.open(UPDATED_TITLES_PATH, std::ofstream::out | std::ofstream::trunc);
updatedTitlesFile.open(path, std::ofstream::out | std::ofstream::trunc);
if(updatedTitlesFile.is_open()) {
while (it != titles.end()){
updatedTitlesFile << (*it) << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion source/list_download_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ListDownloadTab::ListDownloadTab(archiveType type) :
this->description->setText(
"\uE016 This will download a daily updated archive of cheat codes from 'gbatemp.net'. "\
"Cheat codes for games you don't have installed won't be extracted to your SD card. "\
"Title IDs listed in '" + std::string(CHEATS_EXCLUDE) + "' won't recieve cheat updates."
"You can turn off cheat updated in 'Tools->Cheat menu'."
);
break;
}
Expand Down
28 changes: 7 additions & 21 deletions source/tools_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,23 @@

ToolsTab::ToolsTab() : brls::List()
{
viewCheats = new brls::ListItem("View installed cheats");
viewCheats->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new AppPage());
cheats = new brls::ListItem("Cheats menu");
cheats->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new CheatsPage());
});
this->addView(viewCheats);

deleteCheats = new brls::ListItem("Delete all existing cheat codes");
deleteCheats->getClickEvent()->subscribe([&](brls::View* view){
stagedFrame = new brls::StagedAppletFrame();
stagedFrame->setTitle("Delete all cheats");
stagedFrame->addStage(
new WorkerPage(stagedFrame, "Deleting", [](){removeCheats(getCFW());})
);
stagedFrame->addStage(
new ConfirmPage(stagedFrame, "All done!", true)
);
brls::Application::pushView(stagedFrame);
});
this->addView(deleteCheats);
this->addView(cheats);

JCcolor = new brls::ListItem("Change the Joy-Cons color");
JCcolor->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new JCPage());
});
this->addView(JCcolor);

downloadPaysload = new brls::ListItem("Dowload payloads to " + std::string(BOOTLOADER_PL_PATH));
downloadPaysload->getClickEvent()->subscribe([&](brls::View* view){
downloadPayload = new brls::ListItem("Dowload payloads to " + std::string(BOOTLOADER_PL_PATH));
downloadPayload->getClickEvent()->subscribe([&](brls::View* view){
brls::Application::pushView(new DownloadPayloadPage());
});
this->addView(downloadPaysload);
this->addView(downloadPayload);

rebootPayload = new brls::ListItem("Inject payload");
rebootPayload->getClickEvent()->subscribe([&](brls::View* view){
Expand Down

0 comments on commit 42ac921

Please sign in to comment.