Skip to content

Commit

Permalink
Submenus Added
Browse files Browse the repository at this point in the history
Support for cheat submenus has been added. See Readme.
  • Loading branch information
proferabg committed Nov 29, 2021
1 parent 22a30de commit 692be0d
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 20 deletions.
81 changes: 81 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"files.associations": {
"functional": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"filesystem": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"valarray": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif

APP_TITLE := EdiZon
APP_AUTHOR := WerWolv & proferabg
APP_VERSION := v1.0.1
APP_VERSION := v1.0.2

TARGET := EdiZon
OUTDIR := out
Expand Down
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
EdiZon-Overlay by WerWolv
# EdiZon-Overlay

Written by WerWolv

Edited by proferabg

# Changelog

v1.0.1

Updated to libnx 4.2.0

v1.0.2

Submenu Feature Added

# How To Use Submenus

In your cheat text document you can add submenus by using these 2 tags

[--SectionStart:<Section Name>--]
[--SectionEnd:<Section Name>--]

Example:

[--SectionStart:Item Codes--]
00000000 00000000 00000000

[Items x999]
040A0000 01DB2A08 52807CE0

[--SectionEnd:Item Codes--]
00000000 00000000 00000000

This will create a submenu called ***Item Codes*** with ***Items x999*** being a cheat in that submenu.

Warning: Having too many cheats at once can lead to stability issues and can crash.

Updated by proferabg for libnx 4.2.0
112 changes: 95 additions & 17 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@

class GuiCheats : public tsl::Gui {
public:
GuiCheats() { }
GuiCheats(std::string section) {
this->m_section = section;
}
~GuiCheats() { }

virtual tsl::elm::Element* createUI() override {
this->m_cheats = edz::cheat::CheatManager::getCheats();
auto rootFrame = new tsl::elm::OverlayFrame("EdiZon", "Cheats");

if (edz::cheat::CheatManager::getCheats().size() == 0) {
if (m_cheats.size() == 0) {
auto warning = new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, u16 x, u16 y, u16 w, u16 h){
renderer->drawString("\uE150", false, 180, 250, 90, renderer->a(0xFFFF));
renderer->drawString("No Cheats loaded!", false, 110, 340, 25, renderer->a(0xFFFF));
Expand All @@ -57,31 +60,106 @@ class GuiCheats : public tsl::Gui {

} else {
auto list = new tsl::elm::List();

list->addItem(new tsl::elm::CategoryHeader("Available cheats"));

for (auto &cheat : edz::cheat::CheatManager::getCheats()) {
auto cheatToggleItem = new tsl::elm::ToggleListItem(cheat->getName(), cheat->isEnabled());
cheatToggleItem->setStateChangedListener([&cheat](bool state) { cheat->setState(state); });

this->m_cheatToggleItems.push_back(cheatToggleItem);
list->addItem(cheatToggleItem);
std::string head = "Section: " + this->m_section;

if(m_section.length() > 0) list->addItem(new tsl::elm::CategoryHeader(head));
else list->addItem(new tsl::elm::CategoryHeader("Available cheats"));

bool skip = false, inSection = false;
std::string skipUntil = "";

for (auto &cheat : this->m_cheats) {
// Find section start and end
if(this->m_section.length() > 0 && !inSection && cheat->getName().find("--SectionStart:" + this->m_section + "--") == std::string::npos) continue;
else if(cheat->getName().find("--SectionStart:" + this->m_section + "--") != std::string::npos) { inSection = true; continue; }
else if(inSection && cheat->getName().find("--SectionEnd:" + this->m_section + "--") != std::string::npos) break;

// new section
if(!skip && cheat->getName().find("--SectionStart:") != std::string::npos){

//remove formatting
std::string name = cheat->getName();
replaceAll(name, "--", "");
replaceAll(name, "SectionStart:", "");

//create submenu button
auto cheatsSubmenu = new tsl::elm::ListItem(name);
cheatsSubmenu->setClickListener([name = name](s64 keys) {
if (keys & HidNpadButton_A) {
tsl::changeTo<GuiCheats>(name);
return true;
}
return false;
});
list->addItem(cheatsSubmenu);
this->m_numCheats++;

//skip over items in section
skip = true;
skipUntil = "--SectionEnd:" + name + "--";
}
// found end of child section
else if (skip && cheat->getName().compare(skipUntil) == 0){
skip = false;
skipUntil = "";
}
// items to add to section
else if(!skip && inSection) {
auto cheatToggleItem = new tsl::elm::ToggleListItem(cheat->getName(), cheat->isEnabled());
cheatToggleItem->setStateChangedListener([&cheat](bool state) { cheat->setState(state); });

this->m_cheatToggleItems.insert({cheat, cheatToggleItem});
list->addItem(cheatToggleItem);
this->m_numCheats++;
}
}

rootFrame->setContent(list);
// display if no cheats in submenu
if(this->m_numCheats < 1){
auto warning = new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, u16 x, u16 y, u16 w, u16 h){
renderer->drawString("\uE150", false, 180, 250, 90, renderer->a(0xFFFF));
renderer->drawString("No Cheats in Submenu!", false, 110, 340, 25, renderer->a(0xFFFF));
});

rootFrame->setContent(warning);
} else rootFrame->setContent(list);
}

return rootFrame;
}

int FindSectionStart(){
for(u32 i = 0; i < this->m_cheats.size(); i++)
if(this->m_cheats[i]->getName().find("--SectionStart:" + m_section + "--") != std::string::npos) return i + 1;
return 0;
}

int FindSectionEnd(){
for(u32 i = 0; i < this->m_cheats.size(); i++)
if(this->m_cheats[i]->getName().find("--SectionEnd:" + m_section + "--") != std::string::npos) return i;
return this->m_cheats.size();
}

void replaceAll(std::string& str, const std::string& from, const std::string& to) {
if(from.empty())
return;
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}

virtual void update() {
for (u16 i = 0; i < this->m_cheatToggleItems.size(); i++)
this->m_cheatToggleItems[i]->setState(edz::cheat::CheatManager::getCheats()[i]->isEnabled());
for (auto const& [Cheat, Button] : this->m_cheatToggleItems)
Button->setState(Cheat->isEnabled());
}

private:
std::vector<tsl::elm::ToggleListItem*> m_cheatToggleItems;
int m_numCheats = 0;
std::string m_section;
std::vector<edz::cheat::Cheat*> m_cheats;
std::map<edz::cheat::Cheat*, tsl::elm::ToggleListItem*> m_cheatToggleItems;
};

class GuiStats : public tsl::Gui {
Expand Down Expand Up @@ -180,7 +258,7 @@ class GuiMain : public tsl::Gui {
auto *rootFrame = new tsl::elm::HeaderOverlayFrame();
rootFrame->setHeader(new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString("EdiZon", false, 20, 50, 30, renderer->a(tsl::style::color::ColorText));
renderer->drawString("v1.0.1", false, 20, 70, 15, renderer->a(tsl::style::color::ColorDescription));
renderer->drawString("v1.0.2", false, 20, 70, 15, renderer->a(tsl::style::color::ColorDescription));

if (edz::cheat::CheatManager::getProcessID() != 0) {
renderer->drawString("Program ID:", false, 150, 40, 15, renderer->a(tsl::style::color::ColorText));
Expand All @@ -198,7 +276,7 @@ class GuiMain : public tsl::Gui {
auto statsItem = new tsl::elm::ListItem("System information");
cheatsItem->setClickListener([](s64 keys) {
if (keys & HidNpadButton_A) {
tsl::changeTo<GuiCheats>();
tsl::changeTo<GuiCheats>("");
return true;
}

Expand Down

0 comments on commit 692be0d

Please sign in to comment.