citra-emu
/
citra
Archived
1
0
Fork 0

Add cheats in per game configuration (#6379)

This commit is contained in:
luc-git 2023-04-30 16:36:02 +02:00 committed by GitHub
parent ea649263b7
commit 7327c334ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 86 additions and 122 deletions

View File

@ -28,9 +28,6 @@ add_executable(citra-qt
camera/qt_camera_base.h camera/qt_camera_base.h
camera/qt_multimedia_camera.cpp camera/qt_multimedia_camera.cpp
camera/qt_multimedia_camera.h camera/qt_multimedia_camera.h
cheats.cpp
cheats.h
cheats.ui
citra-qt.rc citra-qt.rc
compatdb.cpp compatdb.cpp
compatdb.h compatdb.h
@ -88,6 +85,9 @@ add_executable(citra-qt
configuration/configure_web.cpp configuration/configure_web.cpp
configuration/configure_web.h configuration/configure_web.h
configuration/configure_web.ui configuration/configure_web.ui
configuration/configure_cheats.cpp
configuration/configure_cheats.h
configuration/configure_cheats.ui
debugger/console.h debugger/console.h
debugger/console.cpp debugger/console.cpp
debugger/graphics/graphics.cpp debugger/graphics/graphics.cpp

View File

@ -5,16 +5,16 @@
#include <QCheckBox> #include <QCheckBox>
#include <QMessageBox> #include <QMessageBox>
#include <QTableWidgetItem> #include <QTableWidgetItem>
#include "citra_qt/cheats.h" #include "configure_cheats.h"
#include "core/cheats/cheat_base.h" #include "core/cheats/cheat_base.h"
#include "core/cheats/cheats.h" #include "core/cheats/cheats.h"
#include "core/cheats/gateway_cheat.h" #include "core/cheats/gateway_cheat.h"
#include "core/core.h" #include "core/core.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
#include "ui_cheats.h" #include "ui_configure_cheats.h"
CheatDialog::CheatDialog(QWidget* parent) ConfigureCheats::ConfigureCheats(u64 title_id_, QWidget* parent)
: QDialog(parent), ui(std::make_unique<Ui::CheatDialog>()) { : QWidget(parent), ui(std::make_unique<Ui::ConfigureCheats>()), title_id{title_id_} {
// Setup gui control settings // Setup gui control settings
ui->setupUi(this); ui->setupUi(this);
ui->tableCheats->setColumnWidth(0, 30); ui->tableCheats->setColumnWidth(0, 30);
@ -25,28 +25,26 @@ CheatDialog::CheatDialog(QWidget* parent)
ui->lineName->setEnabled(false); ui->lineName->setEnabled(false);
ui->textCode->setEnabled(false); ui->textCode->setEnabled(false);
ui->textNotes->setEnabled(false); ui->textNotes->setEnabled(false);
const auto game_id = fmt::format(
"{:016X}", Core::System::GetInstance().Kernel().GetCurrentProcess()->codeset->program_id);
ui->labelTitle->setText(tr("Title ID: %1").arg(QString::fromStdString(game_id)));
connect(ui->buttonClose, &QPushButton::clicked, this, &CheatDialog::OnCancel); connect(ui->buttonAddCheat, &QPushButton::clicked, this, &ConfigureCheats::OnAddCheat);
connect(ui->buttonAddCheat, &QPushButton::clicked, this, &CheatDialog::OnAddCheat); connect(ui->tableCheats, &QTableWidget::cellClicked, this, &ConfigureCheats::OnRowSelected);
connect(ui->tableCheats, &QTableWidget::cellClicked, this, &CheatDialog::OnRowSelected); connect(ui->lineName, &QLineEdit::textEdited, this, &ConfigureCheats::OnTextEdited);
connect(ui->lineName, &QLineEdit::textEdited, this, &CheatDialog::OnTextEdited); connect(ui->textNotes, &QPlainTextEdit::textChanged, this, &ConfigureCheats::OnTextEdited);
connect(ui->textNotes, &QPlainTextEdit::textChanged, this, &CheatDialog::OnTextEdited); connect(ui->textCode, &QPlainTextEdit::textChanged, this, &ConfigureCheats::OnTextEdited);
connect(ui->textCode, &QPlainTextEdit::textChanged, this, &CheatDialog::OnTextEdited);
connect(ui->buttonSave, &QPushButton::clicked, this, connect(ui->buttonSave, &QPushButton::clicked, this,
[this] { SaveCheat(ui->tableCheats->currentRow()); }); [this] { SaveCheat(ui->tableCheats->currentRow()); });
connect(ui->buttonDelete, &QPushButton::clicked, this, &CheatDialog::OnDeleteCheat); connect(ui->buttonDelete, &QPushButton::clicked, this, &ConfigureCheats::OnDeleteCheat);
cheat_engine = std::make_unique<Cheats::CheatEngine>(title_id, Core::System::GetInstance());
LoadCheats(); LoadCheats();
} }
CheatDialog::~CheatDialog() = default; ConfigureCheats::~ConfigureCheats() = default;
void CheatDialog::LoadCheats() { void ConfigureCheats::LoadCheats() {
cheats = Core::System::GetInstance().CheatEngine().GetCheats(); cheats = cheat_engine->GetCheats();
const int cheats_count = static_cast<int>(cheats.size()); const int cheats_count = static_cast<int>(cheats.size());
ui->tableCheats->setRowCount(cheats_count); ui->tableCheats->setRowCount(cheats_count);
@ -63,11 +61,11 @@ void CheatDialog::LoadCheats() {
i, 2, new QTableWidgetItem(QString::fromStdString(cheats[i]->GetType()))); i, 2, new QTableWidgetItem(QString::fromStdString(cheats[i]->GetType())));
enabled->setProperty("row", static_cast<int>(i)); enabled->setProperty("row", static_cast<int>(i));
connect(enabled, &QCheckBox::stateChanged, this, &CheatDialog::OnCheckChanged); connect(enabled, &QCheckBox::stateChanged, this, &ConfigureCheats::OnCheckChanged);
} }
} }
bool CheatDialog::CheckSaveCheat() { bool ConfigureCheats::CheckSaveCheat() {
auto answer = QMessageBox::warning( auto answer = QMessageBox::warning(
this, tr("Cheats"), tr("Would you like to save the current cheat?"), this, tr("Cheats"), tr("Would you like to save the current cheat?"),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel); QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel);
@ -79,7 +77,7 @@ bool CheatDialog::CheckSaveCheat() {
} }
} }
bool CheatDialog::SaveCheat(int row) { bool ConfigureCheats::SaveCheat(int row) {
if (ui->lineName->text().isEmpty()) { if (ui->lineName->text().isEmpty()) {
QMessageBox::critical(this, tr("Save Cheat"), tr("Please enter a cheat name.")); QMessageBox::critical(this, tr("Save Cheat"), tr("Please enter a cheat name."));
return false; return false;
@ -110,12 +108,12 @@ bool CheatDialog::SaveCheat(int row) {
ui->textNotes->toPlainText().toStdString()); ui->textNotes->toPlainText().toStdString());
if (newly_created) { if (newly_created) {
Core::System::GetInstance().CheatEngine().AddCheat(cheat); cheat_engine->AddCheat(cheat);
newly_created = false; newly_created = false;
} else { } else {
Core::System::GetInstance().CheatEngine().UpdateCheat(row, cheat); cheat_engine->UpdateCheat(row, cheat);
} }
Core::System::GetInstance().CheatEngine().SaveCheatFile(); cheat_engine->SaveCheatFile();
int previous_row = ui->tableCheats->currentRow(); int previous_row = ui->tableCheats->currentRow();
int previous_col = ui->tableCheats->currentColumn(); int previous_col = ui->tableCheats->currentColumn();
@ -128,19 +126,7 @@ bool CheatDialog::SaveCheat(int row) {
return true; return true;
} }
void CheatDialog::closeEvent(QCloseEvent* event) { void ConfigureCheats::OnRowSelected(int row, int column) {
if (edited && !CheckSaveCheat()) {
event->ignore();
return;
}
event->accept();
}
void CheatDialog::OnCancel() {
close();
}
void CheatDialog::OnRowSelected(int row, int column) {
if (row == last_row) { if (row == last_row) {
return; return;
} }
@ -173,25 +159,24 @@ void CheatDialog::OnRowSelected(int row, int column) {
last_col = column; last_col = column;
} }
void CheatDialog::OnCheckChanged(int state) { void ConfigureCheats::OnCheckChanged(int state) {
const QCheckBox* checkbox = qobject_cast<QCheckBox*>(sender()); const QCheckBox* checkbox = qobject_cast<QCheckBox*>(sender());
int row = static_cast<int>(checkbox->property("row").toInt()); int row = static_cast<int>(checkbox->property("row").toInt());
cheats[row]->SetEnabled(state); cheats[row]->SetEnabled(state);
Core::System::GetInstance().CheatEngine().SaveCheatFile(); cheat_engine->SaveCheatFile();
} }
void CheatDialog::OnTextEdited() { void ConfigureCheats::OnTextEdited() {
edited = true; edited = true;
ui->buttonSave->setEnabled(true); ui->buttonSave->setEnabled(true);
} }
void CheatDialog::OnDeleteCheat() { void ConfigureCheats::OnDeleteCheat() {
if (newly_created) { if (newly_created) {
newly_created = false; newly_created = false;
} else { } else {
auto& cheat_engine = Core::System::GetInstance().CheatEngine(); cheat_engine->RemoveCheat(ui->tableCheats->currentRow());
cheat_engine.RemoveCheat(ui->tableCheats->currentRow()); cheat_engine->SaveCheatFile();
cheat_engine.SaveCheatFile();
} }
LoadCheats(); LoadCheats();
@ -221,7 +206,14 @@ void CheatDialog::OnDeleteCheat() {
ui->buttonAddCheat->setEnabled(true); ui->buttonAddCheat->setEnabled(true);
} }
void CheatDialog::OnAddCheat() { bool ConfigureCheats::ApplyConfiguration() {
if (edited) {
return SaveCheat(ui->tableCheats->currentRow());
}
return true;
}
void ConfigureCheats::OnAddCheat() {
if (edited && !CheckSaveCheat()) { if (edited && !CheckSaveCheat()) {
return; return;
} }

View File

@ -5,22 +5,24 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <QDialog> #include "common/common_types.h"
namespace Cheats { namespace Cheats {
class CheatBase; class CheatBase;
} class CheatEngine;
} // namespace Cheats
namespace Ui { namespace Ui {
class CheatDialog; class ConfigureCheats;
} // namespace Ui } // namespace Ui
class CheatDialog : public QDialog { class ConfigureCheats : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit CheatDialog(QWidget* parent = nullptr); explicit ConfigureCheats(u64 title_id_, QWidget* parent = nullptr);
~CheatDialog(); ~ConfigureCheats();
bool ApplyConfiguration();
private: private:
/** /**
@ -42,10 +44,7 @@ private:
*/ */
bool SaveCheat(int row); bool SaveCheat(int row);
void closeEvent(QCloseEvent* event) override;
private slots: private slots:
void OnCancel();
void OnRowSelected(int row, int column); void OnRowSelected(int row, int column);
void OnCheckChanged(int state); void OnCheckChanged(int state);
void OnTextEdited(); void OnTextEdited();
@ -53,8 +52,10 @@ private slots:
void OnAddCheat(); void OnAddCheat();
private: private:
std::unique_ptr<Ui::CheatDialog> ui; std::unique_ptr<Ui::ConfigureCheats> ui;
std::vector<std::shared_ptr<Cheats::CheatBase>> cheats; std::vector<std::shared_ptr<Cheats::CheatBase>> cheats;
bool edited = false, newly_created = false; bool edited = false, newly_created = false;
int last_row = -1, last_col = -1; int last_row = -1, last_col = -1;
u64 title_id;
std::unique_ptr<Cheats::CheatEngine> cheat_engine;
}; };

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>CheatDialog</class> <class>ConfigureCheats</class>
<widget class="QDialog" name="CheatDialog"> <widget class="QWidget" name="ConfigureCheats">
<property name="windowModality"> <property name="windowModality">
<enum>Qt::ApplicationModal</enum> <enum>Qt::ApplicationModal</enum>
</property> </property>
@ -25,18 +25,6 @@
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="labelTitle">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Title ID:</string>
</property>
</widget>
</item>
<item> <item>
<spacer> <spacer>
<property name="orientation"> <property name="orientation">
@ -208,13 +196,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="buttonClose">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@ -227,7 +208,6 @@
<tabstop>textCode</tabstop> <tabstop>textCode</tabstop>
<tabstop>buttonSave</tabstop> <tabstop>buttonSave</tabstop>
<tabstop>buttonDelete</tabstop> <tabstop>buttonDelete</tabstop>
<tabstop>buttonClose</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -9,6 +9,7 @@
#include <fmt/format.h> #include <fmt/format.h>
#include "citra_qt/configuration/config.h" #include "citra_qt/configuration/config.h"
#include "citra_qt/configuration/configure_audio.h" #include "citra_qt/configuration/configure_audio.h"
#include "citra_qt/configuration/configure_cheats.h"
#include "citra_qt/configuration/configure_debug.h" #include "citra_qt/configuration/configure_debug.h"
#include "citra_qt/configuration/configure_enhancements.h" #include "citra_qt/configuration/configure_enhancements.h"
#include "citra_qt/configuration/configure_general.h" #include "citra_qt/configuration/configure_general.h"
@ -35,6 +36,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const QString
graphics_tab = std::make_unique<ConfigureGraphics>(this); graphics_tab = std::make_unique<ConfigureGraphics>(this);
system_tab = std::make_unique<ConfigureSystem>(this); system_tab = std::make_unique<ConfigureSystem>(this);
debug_tab = std::make_unique<ConfigureDebug>(this); debug_tab = std::make_unique<ConfigureDebug>(this);
cheat_tab = std::make_unique<ConfigureCheats>(title_id, this);
ui->setupUi(this); ui->setupUi(this);
@ -44,6 +46,7 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const QString
ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics")); ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics"));
ui->tabWidget->addTab(audio_tab.get(), tr("Audio")); ui->tabWidget->addTab(audio_tab.get(), tr("Audio"));
ui->tabWidget->addTab(debug_tab.get(), tr("Debug")); ui->tabWidget->addTab(debug_tab.get(), tr("Debug"));
ui->tabWidget->addTab(cheat_tab.get(), tr("Cheats"));
setFocusPolicy(Qt::ClickFocus); setFocusPolicy(Qt::ClickFocus);
setWindowTitle(tr("Properties")); setWindowTitle(tr("Properties"));
@ -60,6 +63,9 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const QString
connect(ui->button_reset_per_game, &QPushButton::clicked, this, connect(ui->button_reset_per_game, &QPushButton::clicked, this,
&ConfigurePerGame::ResetDefaults); &ConfigurePerGame::ResetDefaults);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
&ConfigurePerGame::HandleAcceptedEvent);
LoadConfiguration(); LoadConfiguration();
} }
@ -81,6 +87,13 @@ void ConfigurePerGame::ResetDefaults() {
close(); close();
} }
void ConfigurePerGame::HandleAcceptedEvent() {
if (ui->tabWidget->currentWidget() == cheat_tab.get()) {
cheat_tab->ApplyConfiguration();
}
accept();
}
void ConfigurePerGame::ApplyConfiguration() { void ConfigurePerGame::ApplyConfiguration() {
general_tab->ApplyConfiguration(); general_tab->ApplyConfiguration();
system_tab->ApplyConfiguration(); system_tab->ApplyConfiguration();
@ -109,6 +122,9 @@ void ConfigurePerGame::RetranslateUI() {
void ConfigurePerGame::HandleApplyButtonClicked() { void ConfigurePerGame::HandleApplyButtonClicked() {
ApplyConfiguration(); ApplyConfiguration();
if (ui->tabWidget->currentWidget() == cheat_tab.get()) {
cheat_tab->ApplyConfiguration();
}
} }
static QPixmap GetQPixmapFromSMDH(std::vector<u8>& smdh_data) { static QPixmap GetQPixmapFromSMDH(std::vector<u8>& smdh_data) {

View File

@ -19,6 +19,7 @@ class ConfigureEnhancements;
class ConfigureGraphics; class ConfigureGraphics;
class ConfigureSystem; class ConfigureSystem;
class ConfigureDebug; class ConfigureDebug;
class ConfigureCheats;
class QGraphicsScene; class QGraphicsScene;
class QStandardItem; class QStandardItem;
@ -51,6 +52,7 @@ public:
private: private:
void changeEvent(QEvent* event) override; void changeEvent(QEvent* event) override;
void RetranslateUI(); void RetranslateUI();
void HandleAcceptedEvent();
void HandleApplyButtonClicked(); void HandleApplyButtonClicked();
@ -70,4 +72,5 @@ private:
std::unique_ptr<ConfigureGraphics> graphics_tab; std::unique_ptr<ConfigureGraphics> graphics_tab;
std::unique_ptr<ConfigureSystem> system_tab; std::unique_ptr<ConfigureSystem> system_tab;
std::unique_ptr<ConfigureDebug> debug_tab; std::unique_ptr<ConfigureDebug> debug_tab;
std::unique_ptr<ConfigureCheats> cheat_tab;
}; };

View File

@ -235,22 +235,6 @@
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ConfigurePerGame</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>
<signal>rejected()</signal> <signal>rejected()</signal>

View File

@ -34,7 +34,6 @@
#include "citra_qt/bootmanager.h" #include "citra_qt/bootmanager.h"
#include "citra_qt/camera/qt_multimedia_camera.h" #include "citra_qt/camera/qt_multimedia_camera.h"
#include "citra_qt/camera/still_image_camera.h" #include "citra_qt/camera/still_image_camera.h"
#include "citra_qt/cheats.h"
#include "citra_qt/compatdb.h" #include "citra_qt/compatdb.h"
#include "citra_qt/compatibility_list.h" #include "citra_qt/compatibility_list.h"
#include "citra_qt/configuration/config.h" #include "citra_qt/configuration/config.h"
@ -663,7 +662,6 @@ void GMainWindow::RestoreUIState() {
microProfileDialog->restoreGeometry(UISettings::values.microprofile_geometry); microProfileDialog->restoreGeometry(UISettings::values.microprofile_geometry);
microProfileDialog->setVisible(UISettings::values.microprofile_visible.GetValue()); microProfileDialog->setVisible(UISettings::values.microprofile_visible.GetValue());
#endif #endif
ui->action_Cheats->setEnabled(false);
game_list->LoadInterfaceLayout(); game_list->LoadInterfaceLayout();
@ -765,7 +763,6 @@ void GMainWindow::ConnectMenuEvents() {
connect_menu(ui->action_Report_Compatibility, &GMainWindow::OnMenuReportCompatibility); connect_menu(ui->action_Report_Compatibility, &GMainWindow::OnMenuReportCompatibility);
connect_menu(ui->action_Configure, &GMainWindow::OnConfigure); connect_menu(ui->action_Configure, &GMainWindow::OnConfigure);
connect_menu(ui->action_Configure_Current_Game, &GMainWindow::OnConfigurePerGame); connect_menu(ui->action_Configure_Current_Game, &GMainWindow::OnConfigurePerGame);
connect_menu(ui->action_Cheats, &GMainWindow::OnCheats);
// View // View
connect_menu(ui->action_Single_Window_Mode, &GMainWindow::ToggleWindowMode); connect_menu(ui->action_Single_Window_Mode, &GMainWindow::ToggleWindowMode);
@ -851,7 +848,6 @@ void GMainWindow::UpdateMenuState() {
ui->action_Load_Amiibo, ui->action_Load_Amiibo,
ui->action_Remove_Amiibo, ui->action_Remove_Amiibo,
ui->action_Pause, ui->action_Pause,
ui->action_Cheats,
ui->action_Advance_Frame, ui->action_Advance_Frame,
}; };
@ -1937,11 +1933,6 @@ void GMainWindow::TriggerRotateScreens() {
ui->action_Screen_Layout_Upright_Screens->trigger(); ui->action_Screen_Layout_Upright_Screens->trigger();
} }
void GMainWindow::OnCheats() {
CheatDialog cheat_dialog(this);
cheat_dialog.exec();
}
void GMainWindow::OnSaveState() { void GMainWindow::OnSaveState() {
QAction* action = qobject_cast<QAction*>(sender()); QAction* action = qobject_cast<QAction*>(sender());
assert(action); assert(action);

View File

@ -217,7 +217,6 @@ private slots:
void OnRotateScreens(); void OnRotateScreens();
void TriggerSwapScreens(); void TriggerSwapScreens();
void TriggerRotateScreens(); void TriggerRotateScreens();
void OnCheats();
void ShowFullscreen(); void ShowFullscreen();
void HideFullscreen(); void HideFullscreen();
void ToggleWindowMode(); void ToggleWindowMode();

View File

@ -45,7 +45,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1081</width> <width>1081</width>
<height>25</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu_File"> <widget class="QMenu" name="menu_File">
@ -115,7 +115,6 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_Configure"/> <addaction name="action_Configure"/>
<addaction name="action_Configure_Current_Game"/> <addaction name="action_Configure_Current_Game"/>
<addaction name="action_Cheats"/>
</widget> </widget>
<widget class="QMenu" name="menu_View"> <widget class="QMenu" name="menu_View">
<property name="title"> <property name="title">
@ -333,11 +332,6 @@
<enum>QAction::PreferencesRole</enum> <enum>QAction::PreferencesRole</enum>
</property> </property>
</action> </action>
<action name="action_Cheats">
<property name="text">
<string>Cheats...</string>
</property>
</action>
<action name="action_Display_Dock_Widget_Headers"> <action name="action_Display_Dock_Widget_Headers">
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>

View File

@ -19,9 +19,12 @@ namespace Cheats {
// we use the same value // we use the same value
constexpr u64 run_interval_ticks = 50'000'000; constexpr u64 run_interval_ticks = 50'000'000;
CheatEngine::CheatEngine(Core::System& system_) : system(system_) { CheatEngine::CheatEngine(u64 title_id_, Core::System& system_)
: system(system_), title_id{title_id_} {
LoadCheatFile(); LoadCheatFile();
Connect(); if (system.IsPoweredOn()) {
Connect();
}
} }
void CheatEngine::Connect() { void CheatEngine::Connect() {
@ -32,7 +35,9 @@ void CheatEngine::Connect() {
} }
CheatEngine::~CheatEngine() { CheatEngine::~CheatEngine() {
system.CoreTiming().UnscheduleEvent(event, 0); if (system.IsPoweredOn()) {
system.CoreTiming().UnscheduleEvent(event, 0);
}
} }
std::vector<std::shared_ptr<CheatBase>> CheatEngine::GetCheats() const { std::vector<std::shared_ptr<CheatBase>> CheatEngine::GetCheats() const {
@ -65,8 +70,7 @@ void CheatEngine::UpdateCheat(std::size_t index, const std::shared_ptr<CheatBase
void CheatEngine::SaveCheatFile() const { void CheatEngine::SaveCheatFile() const {
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir); const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
const std::string filepath = fmt::format( const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
"{}{:016X}.txt", cheat_dir, system.Kernel().GetCurrentProcess()->codeset->program_id);
if (!FileUtil::IsDirectory(cheat_dir)) { if (!FileUtil::IsDirectory(cheat_dir)) {
FileUtil::CreateDir(cheat_dir); FileUtil::CreateDir(cheat_dir);
@ -81,8 +85,7 @@ void CheatEngine::SaveCheatFile() const {
void CheatEngine::LoadCheatFile() { void CheatEngine::LoadCheatFile() {
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir); const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
const std::string filepath = fmt::format( const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id);
"{}{:016X}.txt", cheat_dir, system.Kernel().GetCurrentProcess()->codeset->program_id);
if (!FileUtil::IsDirectory(cheat_dir)) { if (!FileUtil::IsDirectory(cheat_dir)) {
FileUtil::CreateDir(cheat_dir); FileUtil::CreateDir(cheat_dir);

View File

@ -24,7 +24,7 @@ class CheatBase;
class CheatEngine { class CheatEngine {
public: public:
explicit CheatEngine(Core::System& system); explicit CheatEngine(u64 title_id_, Core::System& system);
~CheatEngine(); ~CheatEngine();
void Connect(); void Connect();
std::vector<std::shared_ptr<CheatBase>> GetCheats() const; std::vector<std::shared_ptr<CheatBase>> GetCheats() const;
@ -40,5 +40,6 @@ private:
mutable std::shared_mutex cheats_list_mutex; mutable std::shared_mutex cheats_list_mutex;
Core::TimingEventType* event; Core::TimingEventType* event;
Core::System& system; Core::System& system;
u64 title_id;
}; };
} // namespace Cheats } // namespace Cheats

View File

@ -312,12 +312,12 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
} }
} }
kernel->SetCurrentProcess(process); kernel->SetCurrentProcess(process);
cheat_engine = std::make_unique<Cheats::CheatEngine>(*this);
title_id = 0; title_id = 0;
if (app_loader->ReadProgramId(title_id) != Loader::ResultStatus::Success) { if (app_loader->ReadProgramId(title_id) != Loader::ResultStatus::Success) {
LOG_ERROR(Core, "Failed to find title id for ROM (Error {})", LOG_ERROR(Core, "Failed to find title id for ROM (Error {})",
static_cast<u32>(load_result)); static_cast<u32>(load_result));
} }
cheat_engine = std::make_unique<Cheats::CheatEngine>(title_id, *this);
perf_stats = std::make_unique<PerfStats>(title_id); perf_stats = std::make_unique<PerfStats>(title_id);
if (Settings::values.custom_textures) { if (Settings::values.custom_textures) {