diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 81beacd036..b91651d311 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -1167,3 +1167,16 @@ bool CheatsInEffect() { return false; return cheatEngine->HasCheats(); } + +bool DetectCheatTitle(std::string_view name, std::string_view *title) { + // Use Saramagrean title convention (the most common cheats.db file). + const size_t firstOffset = name.find("_[>>>"); + const size_t secondOffset = name.find("<<<]_"); + bool isTitle = firstOffset != std::string::npos && secondOffset != std::string::npos && firstOffset < secondOffset; + if (!isTitle) { + return false; + } + // Extract the title substring. + *title = std::string_view(name.data() + firstOffset + 5, secondOffset - (firstOffset + 5)); + return true; +} diff --git a/Core/CwCheat.h b/Core/CwCheat.h index e697177f17..0e3c6061b3 100644 --- a/Core/CwCheat.h +++ b/Core/CwCheat.h @@ -25,6 +25,8 @@ struct CheatLine { uint32_t part2; }; +bool DetectCheatTitle(std::string_view name, std::string_view *title); + struct CheatCode { std::string name; std::vector lines; @@ -34,6 +36,10 @@ struct CheatFileInfo { int lineNum; std::string name; bool enabled; + + bool IsTitle(std::string_view *title) { + return DetectCheatTitle(name, title); + } }; struct CheatOperation; diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index d37821aea5..bdea09cc43 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -127,9 +127,17 @@ void CwCheatScreen::CreateContentViews(UI::ViewGroup *parent) { rightScroll->Add(rightColumn); rightColumn->Add(new ItemHeader(cw->T("Cheats"))); for (size_t i = 0; i < fileInfo_.size(); ++i) { - rightColumn->Add(new CheckBox(&fileInfo_[i].enabled, fileInfo_[i].name))->OnClick.Add([=](UI::EventParams &) { - OnCheckBox((int)i); - }); + std::string_view title; + if (fileInfo_[i].IsTitle(&title)) { + // Title. + TextView *titleView = rightColumn->Add(new TextView(title, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, UI::Margins(8, 0)))); + titleView->SetTextSize(UI::TextSize::Big); + } else { + // Regular cheat code. + rightColumn->Add(new CheckBox(&fileInfo_[i].enabled, fileInfo_[i].name))->OnClick.Add([=](UI::EventParams &) { + OnCheckBox((int)i); + }); + } } }