Skip to content

Commit

Permalink
Bug fixes and Submenu Disable Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
proferabg committed Jun 26, 2023
1 parent 45dad1d commit 31a9932
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 68 deletions.
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.6
APP_VERSION := v1.0.7

TARGET := EdiZon
OUTDIR := out
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Continued Support by proferabg
<br />
<br />

# Latest Changelog - v1.0.6
# Latest Changelog - v1.0.7

Allow overlay to run when using GDB
Pulled latest libnx with @masagrator's changes
Squashed some more crashing issues!
Fixed mismatched cheats when hiding and showing the overlay.
Added a way to disable submenu logic for those who requested it.
<br />

# How To Use Submenus
Expand All @@ -32,5 +33,11 @@ Example:

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

You can also disable the submenu feature (skips submenu items in cheat file).
To do so, insert the following at the very top of the file.

[--DisableSubmenus--]
00000000 00000000 00000000

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

2 changes: 1 addition & 1 deletion include/cheat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace edz::cheat {

static bool isCheatServiceAvailable();

static bool forceAttach();
static Result forceAttach();
static bool hasCheatProcess();

static u64 getTitleID();
Expand Down
18 changes: 13 additions & 5 deletions source/cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,23 @@ namespace edz::cheat {
return !!running;
}

bool CheatManager::forceAttach() {
Result CheatManager::forceAttach() {
if (!CheatManager::isCheatServiceAvailable())
return ResultEdzCheatServiceNotAvailable;

return Succeeded(dmntchtForceOpenCheatProcess());
uint64_t PID = 0;
for(int i = 0; i < 10; i++) {
if (R_SUCCEEDED(pmdmntGetApplicationProcessId(&PID))) {
return dmntchtForceOpenCheatProcess();
}
svcSleepThread(100'000'000);
}
return ResultEdzAttachFailed;
}

bool CheatManager::hasCheatProcess() {
if (!CheatManager::isCheatServiceAvailable())
return ResultEdzCheatServiceNotAvailable;
if (R_FAILED(CheatManager::forceAttach()))
return false;

bool hasCheatProcess;

Expand Down Expand Up @@ -336,7 +343,8 @@ namespace edz::cheat {

Result res;

CheatManager::forceAttach();
if (R_FAILED(res = CheatManager::forceAttach()))
return res;

// Delete local cheats copy if there are any
for (auto &cheat : CheatManager::s_cheats)
Expand Down
119 changes: 61 additions & 58 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ class GuiCheats : public tsl::Gui {
~GuiCheats() { }

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

if (m_cheats.size() == 0) {
if (edz::cheat::CheatManager::getCheats().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 @@ -65,50 +64,65 @@ class GuiCheats : public tsl::Gui {
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;
bool skip = false, inSection = false, submenus = true;
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++;
for (auto &cheat : edz::cheat::CheatManager::getCheats()) {
if(cheat->getID() == 1 && cheat->getName().find("--DisableSubmenus--") != std::string::npos)
submenus = false;

if(submenus){
// 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 || this->m_section.length() < 1)) {
auto cheatToggleItem = new tsl::elm::ToggleListItem(/*formatString("%d:%s: %s", cheat->getID(), (cheat->isEnabled() ? "y" : "n"),*/ cheat->getName()/*.c_str()).c_str()*/, cheat->isEnabled());
cheatToggleItem->setStateChangedListener([&cheat](bool state) { cheat->setState(state); });

this->m_cheatToggleItems.insert({cheat->getID(), cheatToggleItem});
list->addItem(cheatToggleItem);
this->m_numCheats++;
}
} else {
if(cheat->getName().find("--SectionStart:") != std::string::npos || cheat->getName().find("--SectionEnd:") != std::string::npos || cheat->getName().find("--DisableSubmenus--") != std::string::npos)
continue;

//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 || this->m_section.length() < 1)) {
auto cheatToggleItem = new tsl::elm::ToggleListItem(cheat->getName(), cheat->isEnabled());
cheatToggleItem->setStateChangedListener([&cheat](bool state) { cheat->setState(state); });

this->m_cheatToggleItems.insert({cheat, cheatToggleItem});
this->m_cheatToggleItems.insert({cheat->getID(), cheatToggleItem});
list->addItem(cheatToggleItem);
this->m_numCheats++;
}
Expand All @@ -128,18 +142,6 @@ class GuiCheats : public tsl::Gui {
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;
Expand All @@ -150,16 +152,17 @@ class GuiCheats : public tsl::Gui {
}
}

virtual void update() {
for (auto const& [Cheat, Button] : this->m_cheatToggleItems)
Button->setState(Cheat->isEnabled());
virtual void update() override {
for (auto const& [cheatId, toggleElem] : this->m_cheatToggleItems)
for(auto &cheat : edz::cheat::CheatManager::getCheats())
if(cheat->getID() == cheatId)
toggleElem->setState(cheat->isEnabled());
}

private:
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;
std::map<u32, tsl::elm::ToggleListItem*> m_cheatToggleItems;
};

class GuiStats : public tsl::Gui {
Expand Down Expand Up @@ -288,7 +291,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.6", false, 20, 70, 15, renderer->a(tsl::style::color::ColorDescription));
renderer->drawString("v1.0.7", 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 Down

0 comments on commit 31a9932

Please sign in to comment.