mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-19 02:33:32 +00:00
feat(ui): add per-game cheat management tab with bulk toggle controls
Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
@@ -117,6 +117,9 @@ add_executable(citron
|
||||
configuration/configure_per_game_addons.cpp
|
||||
configuration/configure_per_game_addons.h
|
||||
configuration/configure_per_game_addons.ui
|
||||
configuration/configure_per_game_cheats.cpp
|
||||
configuration/configure_per_game_cheats.h
|
||||
configuration/configure_per_game_cheats.ui
|
||||
configuration/configure_profile_manager.cpp
|
||||
configuration/configure_profile_manager.h
|
||||
configuration/configure_profile_manager.ui
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "citron/configuration/configure_input_per_game.h"
|
||||
#include "citron/configuration/configure_linux_tab.h"
|
||||
#include "citron/configuration/configure_per_game_addons.h"
|
||||
#include "citron/configuration/configure_per_game_cheats.h"
|
||||
#include "citron/configuration/configure_system.h"
|
||||
#include "citron/theme.h"
|
||||
#include "citron/uisettings.h"
|
||||
@@ -107,6 +108,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st
|
||||
|
||||
// Create tab instances
|
||||
addons_tab = std::make_unique<ConfigurePerGameAddons>(system_, this);
|
||||
cheats_tab = std::make_unique<ConfigurePerGameCheats>(system_, this);
|
||||
audio_tab = std::make_unique<ConfigureAudio>(system_, tab_group, *builder, this);
|
||||
cpu_tab = std::make_unique<ConfigureCpu>(system_, tab_group, *builder, this);
|
||||
graphics_advanced_tab =
|
||||
@@ -148,6 +150,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st
|
||||
};
|
||||
|
||||
add_tab(addons_tab.get(), tr("Add-Ons"));
|
||||
add_tab(cheats_tab.get(), tr("Cheats"));
|
||||
add_tab(system_tab.get(), tr("System"));
|
||||
add_tab(cpu_tab.get(), tr("CPU"));
|
||||
add_tab(graphics_tab.get(), tr("Graphics"));
|
||||
@@ -168,6 +171,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
setWindowTitle(tr("Properties"));
|
||||
addons_tab->SetTitleId(title_id);
|
||||
cheats_tab->SetTitleId(title_id);
|
||||
|
||||
scene = new QGraphicsScene;
|
||||
ui->icon_view->setScene(scene);
|
||||
@@ -196,6 +200,7 @@ void ConfigurePerGame::ApplyConfiguration() {
|
||||
tab->ApplyConfiguration();
|
||||
}
|
||||
addons_tab->ApplyConfiguration();
|
||||
cheats_tab->ApplyConfiguration();
|
||||
input_tab->ApplyConfiguration();
|
||||
|
||||
if (Settings::IsDockedMode() && Settings::values.players.GetValue()[0].controller_type ==
|
||||
@@ -310,6 +315,7 @@ void ConfigurePerGame::LoadConfiguration() {
|
||||
}
|
||||
|
||||
addons_tab->LoadFromFile(file);
|
||||
cheats_tab->LoadFromFile(file);
|
||||
|
||||
ui->display_title_id->setText(
|
||||
QStringLiteral("%1").arg(title_id, 16, 16, QLatin1Char{'0'}).toUpper());
|
||||
|
||||
@@ -34,6 +34,7 @@ class InputSubsystem;
|
||||
}
|
||||
|
||||
class ConfigurePerGameAddons;
|
||||
class ConfigurePerGameCheats;
|
||||
class ConfigureAudio;
|
||||
class ConfigureCpu;
|
||||
class ConfigureGraphics;
|
||||
@@ -88,6 +89,7 @@ private:
|
||||
std::shared_ptr<std::vector<ConfigurationShared::Tab*>> tab_group;
|
||||
|
||||
std::unique_ptr<ConfigurePerGameAddons> addons_tab;
|
||||
std::unique_ptr<ConfigurePerGameCheats> cheats_tab;
|
||||
std::unique_ptr<ConfigureAudio> audio_tab;
|
||||
std::unique_ptr<ConfigureCpu> cpu_tab;
|
||||
std::unique_ptr<ConfigureGraphicsAdvanced> graphics_advanced_tab;
|
||||
|
||||
476
src/citron/configuration/configure_per_game_cheats.cpp
Normal file
476
src/citron/configuration/configure_per_game_cheats.cpp
Normal file
@@ -0,0 +1,476 @@
|
||||
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QSignalBlocker>
|
||||
#include <QStandardItemModel>
|
||||
#include <QString>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "common/hex_util.h"
|
||||
#include "common/settings.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/card_image.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
#include "core/file_sys/patch_manager.h"
|
||||
#include "core/file_sys/submission_package.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/loader/loader.h"
|
||||
#include "core/memory/cheat_engine.h"
|
||||
#include "ui_configure_per_game_cheats.h"
|
||||
#include "citron/configuration/configure_per_game_cheats.h"
|
||||
|
||||
ConfigurePerGameCheats::ConfigurePerGameCheats(Core::System& system_, QWidget* parent)
|
||||
: QWidget(parent), ui{std::make_unique<Ui::ConfigurePerGameCheats>()}, system{system_} {
|
||||
ui->setupUi(this);
|
||||
|
||||
layout = new QVBoxLayout;
|
||||
tree_view = new QTreeView;
|
||||
item_model = new QStandardItemModel(tree_view);
|
||||
tree_view->setModel(item_model);
|
||||
tree_view->setAlternatingRowColors(true);
|
||||
tree_view->setSelectionMode(QHeaderView::SingleSelection);
|
||||
tree_view->setSelectionBehavior(QHeaderView::SelectRows);
|
||||
tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel);
|
||||
tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel);
|
||||
tree_view->setSortingEnabled(true);
|
||||
tree_view->setEditTriggers(QHeaderView::NoEditTriggers);
|
||||
tree_view->setUniformRowHeights(true);
|
||||
tree_view->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
|
||||
item_model->insertColumns(0, 1);
|
||||
item_model->setHeaderData(0, Qt::Horizontal, tr("Cheat Name"));
|
||||
|
||||
tree_view->header()->setStretchLastSection(true);
|
||||
|
||||
// We must register all custom types with the Qt Automoc system so that we are able to use it
|
||||
// with signals/slots. In this case, QList falls under the umbrella of custom types.
|
||||
qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
|
||||
|
||||
button_layout = new QHBoxLayout;
|
||||
button_layout->setContentsMargins(0, 0, 0, 0);
|
||||
button_layout->setSpacing(6);
|
||||
|
||||
enable_all_button = new QPushButton(tr("Enable All"));
|
||||
disable_all_button = new QPushButton(tr("Disable All"));
|
||||
save_button = new QPushButton(tr("Save"));
|
||||
|
||||
button_layout->addWidget(enable_all_button);
|
||||
button_layout->addWidget(disable_all_button);
|
||||
button_layout->addStretch();
|
||||
button_layout->addWidget(save_button);
|
||||
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(6);
|
||||
layout->addLayout(button_layout);
|
||||
layout->addWidget(tree_view);
|
||||
|
||||
ui->scrollArea->setLayout(layout);
|
||||
|
||||
connect(item_model, &QStandardItemModel::itemChanged, this,
|
||||
&ConfigurePerGameCheats::OnCheatToggled);
|
||||
connect(enable_all_button, &QPushButton::clicked, this,
|
||||
&ConfigurePerGameCheats::EnableAllCheats);
|
||||
connect(disable_all_button, &QPushButton::clicked, this,
|
||||
&ConfigurePerGameCheats::DisableAllCheats);
|
||||
connect(save_button, &QPushButton::clicked, this,
|
||||
&ConfigurePerGameCheats::SaveCheatSettings);
|
||||
}
|
||||
|
||||
ConfigurePerGameCheats::~ConfigurePerGameCheats() = default;
|
||||
|
||||
void ConfigurePerGameCheats::ApplyConfiguration() {
|
||||
// Settings are updated in OnCheatToggled, but we may need to reload cheats if game is running
|
||||
ReloadCheatEngine();
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::LoadFromFile(FileSys::VirtualFile file_) {
|
||||
file = std::move(file_);
|
||||
LoadConfiguration();
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::SetTitleId(u64 id) {
|
||||
this->title_id = id;
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::changeEvent(QEvent* event) {
|
||||
if (event->type() == QEvent::LanguageChange) {
|
||||
RetranslateUI();
|
||||
}
|
||||
|
||||
QWidget::changeEvent(event);
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::RetranslateUI() {
|
||||
ui->retranslateUi(this);
|
||||
enable_all_button->setText(tr("Enable All"));
|
||||
disable_all_button->setText(tr("Disable All"));
|
||||
save_button->setText(tr("Save"));
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::LoadConfiguration() {
|
||||
if (file == nullptr) {
|
||||
enable_all_button->setEnabled(false);
|
||||
disable_all_button->setEnabled(false);
|
||||
save_button->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto loader = Loader::GetLoader(system, file);
|
||||
|
||||
// Try to get build_id from system first (if game is running)
|
||||
std::array<u8, 0x20> build_id_array{};
|
||||
bool has_build_id = false;
|
||||
|
||||
if (system.IsPoweredOn()) {
|
||||
const auto& current_build_id = system.GetApplicationProcessBuildID();
|
||||
// Check if build_id is not all zeros
|
||||
bool is_valid = false;
|
||||
for (const auto& byte : current_build_id) {
|
||||
if (byte != 0) {
|
||||
is_valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_valid) {
|
||||
build_id_array = current_build_id;
|
||||
has_build_id = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If not available from system, try to extract from file
|
||||
if (!has_build_id) {
|
||||
const auto file_type = loader->GetFileType();
|
||||
|
||||
// Try simple NSO extraction first
|
||||
if (file_type == Loader::FileType::NSO) {
|
||||
if (file->GetSize() >= 0x100) {
|
||||
std::array<u8, 0x100> header_data{};
|
||||
if (file->ReadBytes(header_data.data(), 0x100, 0) == 0x100) {
|
||||
std::memcpy(build_id_array.data(), header_data.data() + 0x40, 0x20);
|
||||
|
||||
// Verify build_id is not all zeros
|
||||
bool is_valid = false;
|
||||
for (const auto& byte : build_id_array) {
|
||||
if (byte != 0) {
|
||||
is_valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
has_build_id = is_valid;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// For other file types, try to get main NSO
|
||||
try {
|
||||
FileSys::VirtualFile main_nso;
|
||||
if (file_type == Loader::FileType::DeconstructedRomDirectory) {
|
||||
// For NSD/deconstructed ROMs, get containing directory and look for main
|
||||
const auto main_dir = file->GetContainingDirectory();
|
||||
if (main_dir) {
|
||||
main_nso = main_dir->GetFile("main");
|
||||
}
|
||||
} else if (file_type == Loader::FileType::NSP) {
|
||||
FileSys::NSP nsp(file);
|
||||
if (nsp.GetStatus() == Loader::ResultStatus::Success) {
|
||||
auto exefs = nsp.GetExeFS();
|
||||
if (exefs) {
|
||||
main_nso = exefs->GetFile("main");
|
||||
}
|
||||
}
|
||||
} else if (file_type == Loader::FileType::XCI) {
|
||||
FileSys::XCI xci(file, title_id, 0);
|
||||
if (xci.GetStatus() == Loader::ResultStatus::Success) {
|
||||
auto program_nca = xci.GetNCAByType(FileSys::NCAContentType::Program);
|
||||
if (program_nca && program_nca->GetStatus() == Loader::ResultStatus::Success) {
|
||||
auto exefs = program_nca->GetExeFS();
|
||||
if (exefs) {
|
||||
main_nso = exefs->GetFile("main");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (file_type == Loader::FileType::NCA) {
|
||||
FileSys::NCA nca(file);
|
||||
if (nca.GetStatus() == Loader::ResultStatus::Success) {
|
||||
auto exefs = nca.GetExeFS();
|
||||
if (exefs) {
|
||||
main_nso = exefs->GetFile("main");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (main_nso && main_nso->GetSize() >= 0x100) {
|
||||
std::array<u8, 0x100> header_data{};
|
||||
if (main_nso->ReadBytes(header_data.data(), 0x100, 0) == 0x100) {
|
||||
std::memcpy(build_id_array.data(), header_data.data() + 0x40, 0x20);
|
||||
|
||||
// Verify build_id is not all zeros
|
||||
bool is_valid = false;
|
||||
for (const auto& byte : build_id_array) {
|
||||
if (byte != 0) {
|
||||
is_valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
has_build_id = is_valid;
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
// Failed to extract build_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_build_id) {
|
||||
// No build_id available, try to use title_id to search for any cheat files
|
||||
// This is a fallback for when we can't extract build_id
|
||||
// We'll try to find cheats in the mod folders
|
||||
const auto load_dir = system.GetFileSystemController().GetModificationLoadRoot(title_id);
|
||||
if (load_dir) {
|
||||
auto patch_dirs = load_dir->GetSubdirectories();
|
||||
for (const auto& subdir : patch_dirs) {
|
||||
if (!subdir) continue;
|
||||
|
||||
// Use case-insensitive directory search (same as FindSubdirectoryCaseless)
|
||||
FileSys::VirtualDir cheats_dir;
|
||||
#ifdef _WIN32
|
||||
cheats_dir = subdir->GetSubdirectory("cheats");
|
||||
#else
|
||||
auto subdirs = subdir->GetSubdirectories();
|
||||
for (const auto& sd : subdirs) {
|
||||
if (sd) {
|
||||
std::string dir_name = Common::ToLower(sd->GetName());
|
||||
if (dir_name == "cheats") {
|
||||
cheats_dir = sd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (cheats_dir) {
|
||||
// Found a cheats directory, try to load any .txt or .pchtxt files
|
||||
auto files = cheats_dir->GetFiles();
|
||||
if (!files.empty()) {
|
||||
// Use the first .txt/.pchtxt file we find to get the build_id from filename
|
||||
for (const auto& cheat_file : files) {
|
||||
const auto& filename = cheat_file->GetName();
|
||||
// Cheat files are named as "BUILDID.txt" where BUILDID is 16 hex chars
|
||||
// They can also be "BUILDID.pchtxt"
|
||||
const bool is_txt = filename.ends_with(".txt");
|
||||
const bool is_pchtxt = filename.ends_with(".pchtxt");
|
||||
|
||||
if ((is_txt || is_pchtxt) && filename.length() >= 20) {
|
||||
// Extract the first 16 characters as the build_id
|
||||
auto potential_build_id = filename.substr(0, 16);
|
||||
|
||||
// Verify it's a valid hex string (case-insensitive)
|
||||
bool is_valid_hex = true;
|
||||
for (char c : potential_build_id) {
|
||||
if (!std::isxdigit(static_cast<unsigned char>(c))) {
|
||||
is_valid_hex = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_valid_hex) {
|
||||
try {
|
||||
// Pad to full 64 chars (32 bytes) with zeros
|
||||
// Keep the case as-is from the filename
|
||||
auto full_build_id_hex = potential_build_id + std::string(48, '0');
|
||||
auto build_id_bytes = Common::HexStringToArray<0x20>(full_build_id_hex);
|
||||
|
||||
// Verify the result is not all zeros
|
||||
bool is_valid_result = false;
|
||||
for (const auto& byte : build_id_bytes) {
|
||||
if (byte != 0) {
|
||||
is_valid_result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_valid_result) {
|
||||
build_id_array = build_id_bytes;
|
||||
has_build_id = true;
|
||||
break;
|
||||
}
|
||||
} catch (...) {
|
||||
// Conversion failed, continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (has_build_id) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_build_id) {
|
||||
// Still no build_id available, can't load cheats
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
build_id_hex = Common::HexToString(build_id_array, false);
|
||||
|
||||
// Get disabled cheats set for this build_id (may be empty initially)
|
||||
const auto& disabled_cheats_set = Settings::values.disabled_cheats[build_id_hex];
|
||||
|
||||
// Load cheats from PatchManager
|
||||
const auto cheats = pm.CreateCheatList(build_id_array);
|
||||
|
||||
// Clear existing items
|
||||
item_model->removeRows(0, item_model->rowCount());
|
||||
list_items.clear();
|
||||
|
||||
const bool has_cheats = !cheats.empty();
|
||||
|
||||
enable_all_button->setEnabled(has_cheats);
|
||||
disable_all_button->setEnabled(has_cheats);
|
||||
save_button->setEnabled(has_cheats);
|
||||
|
||||
if (!has_cheats) {
|
||||
// No cheats available for this game
|
||||
// This could mean:
|
||||
// 1. No cheat files found
|
||||
// 2. The mod containing cheats is disabled in Add-Ons tab
|
||||
// 3. Build ID mismatch between file and what we extracted
|
||||
return;
|
||||
}
|
||||
|
||||
// Add cheats to tree view
|
||||
for (const auto& cheat : cheats) {
|
||||
// Extract cheat name from readable_name (null-terminated)
|
||||
const std::string cheat_name_str(cheat.definition.readable_name.data(),
|
||||
strnlen(cheat.definition.readable_name.data(),
|
||||
cheat.definition.readable_name.size()));
|
||||
|
||||
// Skip empty cheat names or cheats with no opcodes
|
||||
if (cheat_name_str.empty() || cheat.definition.num_opcodes == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto cheat_name = QString::fromStdString(cheat_name_str);
|
||||
|
||||
auto* const cheat_item = new QStandardItem;
|
||||
cheat_item->setText(cheat_name);
|
||||
cheat_item->setCheckable(true);
|
||||
|
||||
// Check if cheat is disabled
|
||||
const bool cheat_disabled = disabled_cheats_set.find(cheat_name_str) != disabled_cheats_set.end();
|
||||
cheat_item->setCheckState(cheat_disabled ? Qt::Unchecked : Qt::Checked);
|
||||
|
||||
list_items.push_back(QList<QStandardItem*>{cheat_item});
|
||||
item_model->appendRow(list_items.back());
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::OnCheatToggled(QStandardItem* item) {
|
||||
if (build_id_hex.empty() || item == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string cheat_name = item->text().toStdString();
|
||||
auto& disabled_cheats_set = Settings::values.disabled_cheats[build_id_hex];
|
||||
|
||||
const bool is_checked = item->checkState() == Qt::Checked;
|
||||
|
||||
if (is_checked) {
|
||||
// Enable cheat - remove from disabled set
|
||||
disabled_cheats_set.erase(cheat_name);
|
||||
} else {
|
||||
// Disable cheat - add to disabled set
|
||||
disabled_cheats_set.insert(cheat_name);
|
||||
}
|
||||
|
||||
ReloadCheatEngine();
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::EnableAllCheats() {
|
||||
SetAllCheats(true);
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::DisableAllCheats() {
|
||||
SetAllCheats(false);
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::SaveCheatSettings() {
|
||||
ApplyConfiguration();
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::SetAllCheats(bool enabled) {
|
||||
if (build_id_hex.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& disabled_set = Settings::values.disabled_cheats[build_id_hex];
|
||||
|
||||
QSignalBlocker blocker(item_model);
|
||||
|
||||
if (enabled) {
|
||||
disabled_set.clear();
|
||||
} else {
|
||||
disabled_set.clear();
|
||||
}
|
||||
|
||||
for (auto& items : list_items) {
|
||||
if (items.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* item = items.front();
|
||||
if (item == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
|
||||
|
||||
if (!enabled) {
|
||||
disabled_set.insert(item->text().toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
// Ensure no disabled cheats remain when enabling all
|
||||
disabled_set.clear();
|
||||
}
|
||||
|
||||
blocker.unblock();
|
||||
|
||||
// Emit data changed to refresh view
|
||||
if (item_model->rowCount() > 0) {
|
||||
item_model->dataChanged(item_model->index(0, 0),
|
||||
item_model->index(item_model->rowCount() - 1, 0));
|
||||
}
|
||||
|
||||
ReloadCheatEngine();
|
||||
}
|
||||
|
||||
void ConfigurePerGameCheats::ReloadCheatEngine() const {
|
||||
if (!system.IsPoweredOn()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* cheat_engine = system.GetCheatEngine();
|
||||
if (cheat_engine == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto& current_build_id = system.GetApplicationProcessBuildID();
|
||||
const auto cheats = pm.CreateCheatList(current_build_id);
|
||||
cheat_engine->Reload(cheats);
|
||||
}
|
||||
72
src/citron/configuration/configure_per_game_cheats.h
Normal file
72
src/citron/configuration/configure_per_game_cheats.h
Normal file
@@ -0,0 +1,72 @@
|
||||
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <QList>
|
||||
#include <QWidget>
|
||||
|
||||
#include "core/file_sys/vfs/vfs_types.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
class QHBoxLayout;
|
||||
class QPushButton;
|
||||
class QStandardItem;
|
||||
class QStandardItemModel;
|
||||
class QTreeView;
|
||||
class QVBoxLayout;
|
||||
|
||||
namespace Ui {
|
||||
class ConfigurePerGameCheats;
|
||||
}
|
||||
|
||||
class ConfigurePerGameCheats : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ConfigurePerGameCheats(Core::System& system_, QWidget* parent = nullptr);
|
||||
~ConfigurePerGameCheats() override;
|
||||
|
||||
/// Save all cheat configurations to settings file
|
||||
void ApplyConfiguration();
|
||||
|
||||
void LoadFromFile(FileSys::VirtualFile file_);
|
||||
|
||||
void SetTitleId(u64 id);
|
||||
|
||||
private:
|
||||
void changeEvent(QEvent* event) override;
|
||||
void RetranslateUI();
|
||||
|
||||
void LoadConfiguration();
|
||||
void OnCheatToggled(QStandardItem* item);
|
||||
void EnableAllCheats();
|
||||
void DisableAllCheats();
|
||||
void SaveCheatSettings();
|
||||
void SetAllCheats(bool enabled);
|
||||
void ReloadCheatEngine() const;
|
||||
|
||||
std::unique_ptr<Ui::ConfigurePerGameCheats> ui;
|
||||
FileSys::VirtualFile file;
|
||||
u64 title_id;
|
||||
std::string build_id_hex;
|
||||
|
||||
QHBoxLayout* button_layout;
|
||||
QPushButton* enable_all_button;
|
||||
QPushButton* disable_all_button;
|
||||
QPushButton* save_button;
|
||||
|
||||
QVBoxLayout* layout;
|
||||
QTreeView* tree_view;
|
||||
QStandardItemModel* item_model;
|
||||
|
||||
std::vector<QList<QStandardItem*>> list_items;
|
||||
|
||||
Core::System& system;
|
||||
};
|
||||
41
src/citron/configuration/configure_per_game_cheats.ui
Normal file
41
src/citron/configuration/configure_per_game_cheats.ui
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ConfigurePerGameCheats</class>
|
||||
<widget class="QWidget" name="ConfigurePerGameCheats">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="accessibleDescription">
|
||||
<string>Cheats</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>380</width>
|
||||
<height>280</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -677,6 +678,10 @@ struct Values {
|
||||
|
||||
// Add-Ons
|
||||
std::map<u64, std::vector<std::string>> disabled_addons;
|
||||
|
||||
// Cheats
|
||||
// Key: build_id (hex string), Value: set of disabled cheat names
|
||||
std::map<std::string, std::set<std::string>> disabled_cheats;
|
||||
};
|
||||
|
||||
extern Values values;
|
||||
|
||||
@@ -830,6 +830,14 @@ void System::RegisterCheatList(const std::vector<Memory::CheatEntry>& list,
|
||||
impl->cheat_engine->SetMainMemoryParameters(main_region_begin, main_region_size);
|
||||
}
|
||||
|
||||
Memory::CheatEngine* System::GetCheatEngine() {
|
||||
return impl->cheat_engine.get();
|
||||
}
|
||||
|
||||
const Memory::CheatEngine* System::GetCheatEngine() const {
|
||||
return impl->cheat_engine.get();
|
||||
}
|
||||
|
||||
void System::SetFrontendAppletSet(Service::AM::Frontend::FrontendAppletSet&& set) {
|
||||
impl->frontend_applets.SetFrontendAppletSet(std::move(set));
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ enum class ResultStatus : u16;
|
||||
|
||||
namespace Core::Memory {
|
||||
struct CheatEntry;
|
||||
class CheatEngine;
|
||||
class Memory;
|
||||
} // namespace Core::Memory
|
||||
|
||||
@@ -349,6 +350,9 @@ public:
|
||||
const std::array<u8, 0x20>& build_id, u64 main_region_begin,
|
||||
u64 main_region_size);
|
||||
|
||||
[[nodiscard]] Memory::CheatEngine* GetCheatEngine();
|
||||
[[nodiscard]] const Memory::CheatEngine* GetCheatEngine() const;
|
||||
|
||||
void SetFrontendAppletSet(Service::AM::Frontend::FrontendAppletSet&& set);
|
||||
|
||||
[[nodiscard]] Service::AM::Frontend::FrontendAppletHolder& GetFrontendAppletHolder();
|
||||
|
||||
@@ -339,6 +339,30 @@ void Config::ReadDisabledAddOnValues() {
|
||||
EndGroup();
|
||||
}
|
||||
|
||||
void Config::ReadDisabledCheatValues() {
|
||||
// Custom config section
|
||||
BeginGroup(std::string("DisabledCheats"));
|
||||
|
||||
const int size = BeginArray(std::string(""));
|
||||
for (int i = 0; i < size; ++i) {
|
||||
SetArrayIndex(i);
|
||||
const auto build_id = ReadStringSetting(std::string("build_id"), std::string(""));
|
||||
std::set<std::string> out;
|
||||
const int d_size = BeginArray("disabled");
|
||||
for (int j = 0; j < d_size; ++j) {
|
||||
SetArrayIndex(j);
|
||||
out.insert(ReadStringSetting(std::string("d"), std::string("")));
|
||||
}
|
||||
EndArray(); // disabled
|
||||
if (!build_id.empty()) {
|
||||
Settings::values.disabled_cheats.insert_or_assign(build_id, out);
|
||||
}
|
||||
}
|
||||
EndArray(); // Base disabled cheats array - Has no base key
|
||||
|
||||
EndGroup();
|
||||
}
|
||||
|
||||
void Config::ReadMiscellaneousValues() {
|
||||
BeginGroup(Settings::TranslateCategory(Settings::Category::Miscellaneous));
|
||||
|
||||
@@ -415,6 +439,7 @@ void Config::ReadValues() {
|
||||
ReadDataStorageValues();
|
||||
ReadDebuggingValues();
|
||||
ReadDisabledAddOnValues();
|
||||
ReadDisabledCheatValues();
|
||||
ReadNetworkValues();
|
||||
ReadServiceValues();
|
||||
ReadWebServiceValues();
|
||||
@@ -518,6 +543,7 @@ void Config::SaveValues() {
|
||||
SaveDataStorageValues();
|
||||
SaveDebuggingValues();
|
||||
SaveDisabledAddOnValues();
|
||||
SaveDisabledCheatValues();
|
||||
SaveNetworkValues();
|
||||
SaveWebServiceValues();
|
||||
SaveMiscellaneousValues();
|
||||
@@ -647,6 +673,32 @@ void Config::SaveDisabledAddOnValues() {
|
||||
EndGroup();
|
||||
}
|
||||
|
||||
void Config::SaveDisabledCheatValues() {
|
||||
// Custom config section
|
||||
BeginGroup(std::string("DisabledCheats"));
|
||||
|
||||
int i = 0;
|
||||
BeginArray(std::string(""));
|
||||
for (const auto& elem : Settings::values.disabled_cheats) {
|
||||
SetArrayIndex(i);
|
||||
WriteStringSetting(std::string("build_id"), elem.first,
|
||||
std::make_optional(std::string("")));
|
||||
BeginArray(std::string("disabled"));
|
||||
int j = 0;
|
||||
for (const auto& cheat_name : elem.second) {
|
||||
SetArrayIndex(j);
|
||||
WriteStringSetting(std::string("d"), cheat_name,
|
||||
std::make_optional(std::string("")));
|
||||
++j;
|
||||
}
|
||||
EndArray(); // disabled
|
||||
++i;
|
||||
}
|
||||
EndArray(); // Base disabled cheats array - Has no base key
|
||||
|
||||
EndGroup();
|
||||
}
|
||||
|
||||
void Config::SaveMiscellaneousValues() {
|
||||
BeginGroup(Settings::TranslateCategory(Settings::Category::Miscellaneous));
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ protected:
|
||||
#endif
|
||||
void ReadServiceValues();
|
||||
void ReadDisabledAddOnValues();
|
||||
void ReadDisabledCheatValues();
|
||||
void ReadMiscellaneousValues();
|
||||
void ReadCpuValues();
|
||||
void ReadRendererValues();
|
||||
@@ -116,6 +117,7 @@ protected:
|
||||
#endif
|
||||
void SaveNetworkValues();
|
||||
void SaveDisabledAddOnValues();
|
||||
void SaveDisabledCheatValues();
|
||||
void SaveMiscellaneousValues();
|
||||
void SaveCpuValues();
|
||||
void SaveRendererValues();
|
||||
|
||||
Reference in New Issue
Block a user