From ea28e6d0d928e6d8b99c06265d14ccec8173d3d5 Mon Sep 17 00:00:00 2001 From: BearOso Date: Mon, 14 Aug 2023 09:34:19 -0500 Subject: [PATCH] Qt: Add unworking cheats window. --- cheats.h | 45 ++++++++------- qt/CMakeLists.txt | 1 + qt/src/CheatsDialog.cpp | 27 +++++++++ qt/src/CheatsDialog.hpp | 12 ++++ qt/src/CheatsDialog.ui | 118 +++++++++++++++++++++++++++++++++++++++ qt/src/EmuMainWindow.cpp | 11 +++- 6 files changed, 192 insertions(+), 22 deletions(-) create mode 100644 qt/src/CheatsDialog.cpp create mode 100644 qt/src/CheatsDialog.hpp create mode 100644 qt/src/CheatsDialog.ui diff --git a/cheats.h b/cheats.h index fbc15982..9afee6df 100644 --- a/cheats.h +++ b/cheats.h @@ -7,17 +7,20 @@ #ifndef _CHEATS_H_ #define _CHEATS_H_ -#include "port.h" +#include +#include #include +using bool8 = uint8_t; + struct SCheat { - uint32 address; - uint8 byte; - uint8 saved_byte; + uint32_t address; + uint8_t byte; + uint8_t saved_byte; bool8 conditional; bool8 cond_true; - uint8 cond_byte; + uint8_t cond_byte; bool8 enabled; }; @@ -32,14 +35,14 @@ struct SCheatData { std::vector group; bool8 enabled; - uint8 CWRAM[0x20000]; - uint8 CSRAM[0x80000]; - uint8 CIRAM[0x2000]; - uint8 *RAM; - uint8 *FillRAM; - uint8 *SRAM; - uint32 ALL_BITS[0x32000 >> 5]; - uint8 CWatchRAM[0x32000]; + uint8_t CWRAM[0x20000]; + uint8_t CSRAM[0x80000]; + uint8_t CIRAM[0x2000]; + uint8_t *RAM; + uint8_t *FillRAM; + uint8_t *SRAM; + uint32_t ALL_BITS[0x32000 >> 5]; + uint8_t CWatchRAM[0x32000]; }; struct Watch @@ -47,7 +50,7 @@ struct Watch bool on; int size; int format; - uint32 address; + uint32_t address; char buf[12]; char desc[32]; }; @@ -74,12 +77,12 @@ extern SCheatData Cheat; extern Watch watches[16]; int S9xAddCheatGroup(const std::string &name, const std::string &cheat); -int S9xModifyCheatGroup(uint32 index, const std::string &name, const std::string &cheat); -void S9xEnableCheatGroup(uint32 index); -void S9xDisableCheatGroup(uint32 index); +int S9xModifyCheatGroup(uint32_t index, const std::string &name, const std::string &cheat); +void S9xEnableCheatGroup(uint32_t index); +void S9xDisableCheatGroup(uint32_t index); void S9xDeleteCheats(void); -std::string S9xCheatGroupToText(uint32 index); -void S9xDeleteCheatGroup(uint32 index); +std::string S9xCheatGroupToText(uint32_t index); +void S9xDeleteCheatGroup(uint32_t index); bool8 S9xLoadCheatFile(const std::string &filename); bool8 S9xSaveCheatFile(const std::string &filename); void S9xUpdateCheatsInMemory(void); @@ -92,8 +95,8 @@ void S9xInitCheatData (void); void S9xInitWatchedAddress (void); void S9xStartCheatSearch (SCheatData *); void S9xSearchForChange (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, bool8, bool8); -void S9xSearchForValue (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, uint32, bool8, bool8); -void S9xSearchForAddress (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, uint32, bool8); +void S9xSearchForValue (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, uint32_t, bool8, bool8); +void S9xSearchForAddress (SCheatData *, S9xCheatComparisonType, S9xCheatDataSize, uint32_t, bool8); void S9xOutputCheatSearchResults (SCheatData *); #endif diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index b54d6c2c..ae7ce3ea 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -146,6 +146,7 @@ list(APPEND QT_GUI_SOURCES src/FoldersPanel.cpp src/SDLInputManager.cpp src/ShaderParametersDialog.cpp + src/CheatsDialog.cpp src/SoftwareScalers.cpp src/EmuCanvasQt.cpp src/EmuCanvasOpenGL.cpp diff --git a/qt/src/CheatsDialog.cpp b/qt/src/CheatsDialog.cpp new file mode 100644 index 00000000..6a922796 --- /dev/null +++ b/qt/src/CheatsDialog.cpp @@ -0,0 +1,27 @@ +#include "CheatsDialog.hpp" + +static const auto desired_flags = Qt::ItemFlag::ItemIsUserCheckable | + Qt::ItemFlag::ItemIsEnabled | + Qt::ItemFlag::ItemIsSelectable | + Qt::ItemFlag::ItemIsDragEnabled; + +CheatsDialog::CheatsDialog(QWidget *parent, EmuApplication *app_) + : app(app_), QDialog(parent) +{ + setupUi(this); + show(); + + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setFlags(desired_flags); + item->setCheckState(0, Qt::CheckState::Checked); + item->setText(1, "Invincibility"); + item->setText(2, "dd32-6dad"); + + treeWidget_cheats->insertTopLevelItem(0, item); + item = new QTreeWidgetItem(); + item->setFlags(desired_flags); + item->setCheckState(0, Qt::CheckState::Checked); + item->setText(1, "Torzx"); + item->setText(2, "7e0fff:ff\n7e0ff7:ff"); + treeWidget_cheats->insertTopLevelItem(1, item); +} \ No newline at end of file diff --git a/qt/src/CheatsDialog.hpp b/qt/src/CheatsDialog.hpp new file mode 100644 index 00000000..3bd5f836 --- /dev/null +++ b/qt/src/CheatsDialog.hpp @@ -0,0 +1,12 @@ +#include "ui_CheatsDialog.h" + +class EmuApplication; + +class CheatsDialog : public QDialog, public Ui_Dialog +{ + public: + CheatsDialog(QWidget *parent, EmuApplication *app); + + EmuApplication *app; +}; + diff --git a/qt/src/CheatsDialog.ui b/qt/src/CheatsDialog.ui new file mode 100644 index 00000000..e4da6dec --- /dev/null +++ b/qt/src/CheatsDialog.ui @@ -0,0 +1,118 @@ + + + Dialog + + + + 0 + 0 + 466 + 399 + + + + Dialog + + + + + + + + Code: + + + + + + + + + + Description: + + + + + + + + + + + + + + Add + + + + + + + Update + + + + + + + Remove + + + + + + + Remove All + + + + + + + Check Database + + + + + + + + + false + + + false + + + + Enabled + + + + + Description + + + + + Code + + + + + + + + lineEdit_description + lineEdit_code + pushButton_add + pushButton_update + pushButton_remove + pushButton_remove_all + pushButton_check_database + + + + diff --git a/qt/src/EmuMainWindow.cpp b/qt/src/EmuMainWindow.cpp index f398418a..bf29e04f 100644 --- a/qt/src/EmuMainWindow.cpp +++ b/qt/src/EmuMainWindow.cpp @@ -17,7 +17,8 @@ #include "EmuCanvasVulkan.hpp" #include "EmuCanvasOpenGL.hpp" #include "EmuCanvasQt.hpp" -#include "src/ShaderParametersDialog.hpp" +#include "CheatsDialog.hpp" +#include "ShaderParametersDialog.hpp" #undef KeyPress static EmuSettingsWindow *g_emu_settings_window = nullptr; @@ -260,6 +261,14 @@ void EmuMainWindow::createWidgets() }); core_actions.push_back(hard_reset_item); + emulation_menu->addSeparator(); + + auto cheats_item = emulation_menu->addAction(tr("&Cheats")); + connect(cheats_item, &QAction::triggered, [&] { + auto cheats_dialog = new CheatsDialog(this, app); + }); + core_actions.push_back(cheats_item); + menuBar()->addMenu(emulation_menu); // View Menu