Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CheatEngine and support for Gateway cheats #4406

Merged
merged 16 commits into from Nov 17, 2018
@@ -24,6 +24,8 @@ add_executable(citra-qt
camera/qt_camera_base.h
camera/qt_multimedia_camera.cpp
camera/qt_multimedia_camera.h
cheats.cpp
cheats.h
citra-qt.rc
configuration/config.cpp
configuration/config.h
@@ -134,6 +136,7 @@ set(UIS
multiplayer/client_room.ui
multiplayer/host_room.ui
aboutdialog.ui
cheats.ui
hotkeys.ui
main.ui
compatdb.ui
@@ -0,0 +1,84 @@
// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QLineEdit>
This conversation was marked as resolved by B3n30

This comment has been minimized.

Copy link
@zhaowenlan1779

zhaowenlan1779 Nov 10, 2018

Member

I think some of these are not necessary

#include <QTableWidgetItem>
#include "citra_qt/cheats.h"
#include "core/core.h"
#include "core/hle/kernel/process.h"
#include "ui_cheats.h"

CheatDialog::CheatDialog(QWidget* parent)
: QDialog(parent), ui(std::make_unique<Ui::CheatDialog>()) {
// Setup gui control settings
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
ui->tableCheats->setColumnWidth(0, 30);
ui->tableCheats->setColumnWidth(2, 85);
ui->tableCheats->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
ui->tableCheats->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
ui->tableCheats->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
ui->textDetails->setEnabled(false);
ui->textNotes->setEnabled(false);
This conversation was marked as resolved by B3n30

This comment has been minimized.

Copy link
@zhaowenlan1779

zhaowenlan1779 Nov 7, 2018

Member

I have a feeling that a lot of these can be put in the ui file instead.

This comment has been minimized.

Copy link
@B3n30

B3n30 Nov 7, 2018

Author Contributor

I moved as much as possible (afaik) into the ui file. All the remaining part should be part of the code.

Note that setEnabled was placed on purpose in the constructor

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::released, this, &CheatDialog::OnCancel);
connect(ui->tableCheats, &QTableWidget::cellClicked, this, &CheatDialog::OnRowSelected);

LoadCheats();
}

CheatDialog::~CheatDialog() = default;

void CheatDialog::LoadCheats() {
cheats = Core::System::GetInstance().CheatEngine().GetCheats();

ui->tableCheats->setRowCount(cheats.size());

for (size_t i = 0; i < cheats.size(); i++) {
QCheckBox* enabled = new QCheckBox();
enabled->setChecked(cheats[i]->GetEnabled());
enabled->setStyleSheet("margin-left:7px;");
This conversation was marked as resolved by B3n30

This comment has been minimized.

Copy link
@zhaowenlan1779

zhaowenlan1779 Nov 7, 2018

Member

Must this be set via stylesheet? i.e. isn't there any direct margin setter?

This comment has been minimized.

Copy link
@B3n30

B3n30 Nov 7, 2018

Author Contributor

thats the only one line solution I know, thus Imo it's fine

ui->tableCheats->setItem(i, 0, new QTableWidgetItem());
ui->tableCheats->setCellWidget(i, 0, enabled);
ui->tableCheats->setItem(
i, 1, new QTableWidgetItem(QString::fromStdString(cheats[i]->GetName())));
ui->tableCheats->setItem(
i, 2, new QTableWidgetItem(QString::fromStdString(cheats[i]->GetType())));
enabled->setProperty("row", static_cast<int>(i));

connect(enabled, &QCheckBox::stateChanged, this, &CheatDialog::OnCheckChanged);
}
}

void CheatDialog::OnCancel() {
close();
}

void CheatDialog::OnRowSelected(int row, int column) {
if (row == -1) {
This conversation was marked as resolved by B3n30

This comment has been minimized.

Copy link
@FearlessTobi

FearlessTobi Nov 7, 2018

Contributor

Is there a scenario where this is even possible?

ui->textNotes->setPlainText("");
ui->textDetails->setPlainText("");
ui->textDetails->setEnabled(false);
ui->textNotes->setEnabled(false);
return;
}

ui->textDetails->setEnabled(true);
ui->textNotes->setEnabled(true);
const auto& current_cheat = cheats[row];
ui->textNotes->setPlainText(QString::fromStdString(current_cheat->GetComments()));
ui->textDetails->setPlainText(QString::fromStdString(current_cheat->ToString()));
}

void CheatDialog::OnCheckChanged(int state) {
const QCheckBox* checkbox = qobject_cast<QCheckBox*>(sender());
int row = static_cast<int>(checkbox->property("row").toInt());
cheats[row]->SetEnabled(state);
}
@@ -0,0 +1,36 @@
// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <memory>
#include <QDialog>
#include "core/cheats/cheats.h"
This conversation was marked as resolved by zhaowenlan1779

This comment has been minimized.

Copy link
@zhaowenlan1779

zhaowenlan1779 Nov 10, 2018

Member

This can likely be a forward declaration.

This comment has been minimized.

Copy link
@B3n30

B3n30 Nov 10, 2018

Author Contributor

nope, it can't

This comment has been minimized.

Copy link
@zhaowenlan1779

zhaowenlan1779 Nov 10, 2018

Member

Oh, then this can be moved to the cpp file.


class QComboBox;
class QLineEdit;
class QWidget;
This conversation was marked as resolved by B3n30

This comment has been minimized.

Copy link
@zhaowenlan1779

zhaowenlan1779 Nov 10, 2018

Member

where are these used?

namespace Ui {
class CheatDialog;
class NewCheatDialog;
This conversation was marked as resolved by B3n30

This comment has been minimized.

Copy link
@zhaowenlan1779

zhaowenlan1779 Nov 10, 2018

Member

This should be removed

} // namespace Ui

class CheatDialog : public QDialog {
Q_OBJECT

public:
explicit CheatDialog(QWidget* parent = nullptr);
~CheatDialog();

private:
std::unique_ptr<Ui::CheatDialog> ui;
std::vector<std::shared_ptr<Cheats::CheatBase>> cheats;

void LoadCheats();

private slots:
void OnCancel();
void OnRowSelected(int row, int column);
void OnCheckChanged(int state);
};
@@ -0,0 +1,204 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CheatDialog</class>
<widget class="QDialog" name="CheatDialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>862</width>
<height>612</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Cheats</string>
</property>
<widget class="QLabel" name="labelTitle">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>300</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Title ID:</string>
</property>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>570</y>
<width>841</width>
<height>41</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonClose">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>551</width>
<height>471</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="tableCheats">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="columnCount">
<number>3</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string/>
</property>
</column>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QLabel" name="labelAvailableCheats">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>121</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Available Cheats:</string>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_2">
<property name="geometry">
<rect>
<x>580</x>
<y>440</y>
<width>271</width>
<height>111</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPlainTextEdit" name="textNotes">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QLabel" name="labelNotes">
<property name="geometry">
<rect>
<x>580</x>
<y>420</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Notes:</string>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_3">
<property name="geometry">
<rect>
<x>580</x>
<y>80</y>
<width>271</width>
<height>311</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPlainTextEdit" name="textDetails">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QLabel" name="labelDetails">
<property name="geometry">
<rect>
<x>580</x>
<y>60</y>
<width>55</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Code:</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
@@ -20,6 +20,7 @@
#include "citra_qt/bootmanager.h"
#include "citra_qt/camera/qt_multimedia_camera.h"
#include "citra_qt/camera/still_image_camera.h"
#include "citra_qt/cheats.h"
#include "citra_qt/compatdb.h"
#include "citra_qt/compatibility_list.h"
#include "citra_qt/configuration/config.h"
@@ -449,6 +450,7 @@ void GMainWindow::RestoreUIState() {
microProfileDialog->restoreGeometry(UISettings::values.microprofile_geometry);
microProfileDialog->setVisible(UISettings::values.microprofile_visible);
#endif
ui.action_Cheats->setEnabled(false);

game_list->LoadInterfaceLayout();

@@ -509,6 +511,7 @@ void GMainWindow::ConnectMenuEvents() {
connect(ui.action_Report_Compatibility, &QAction::triggered, this,
&GMainWindow::OnMenuReportCompatibility);
connect(ui.action_Configure, &QAction::triggered, this, &GMainWindow::OnConfigure);
connect(ui.action_Cheats, &QAction::triggered, this, &GMainWindow::OnCheats);

// View
connect(ui.action_Single_Window_Mode, &QAction::triggered, this,
@@ -852,6 +855,7 @@ void GMainWindow::ShutdownGame() {
ui.action_Pause->setEnabled(false);
ui.action_Stop->setEnabled(false);
ui.action_Restart->setEnabled(false);
ui.action_Cheats->setEnabled(false);
ui.action_Load_Amiibo->setEnabled(false);
ui.action_Remove_Amiibo->setEnabled(false);
ui.action_Report_Compatibility->setEnabled(false);
@@ -1141,6 +1145,7 @@ void GMainWindow::OnStartGame() {
ui.action_Pause->setEnabled(true);
ui.action_Stop->setEnabled(true);
ui.action_Restart->setEnabled(true);
ui.action_Cheats->setEnabled(true);
ui.action_Load_Amiibo->setEnabled(true);
ui.action_Report_Compatibility->setEnabled(true);
ui.action_Enable_Frame_Advancing->setEnabled(true);
@@ -1276,6 +1281,11 @@ void GMainWindow::OnSwapScreens() {
Settings::Apply();
}

void GMainWindow::OnCheats() {
CheatDialog cheat_dialog(this);
cheat_dialog.exec();
}

void GMainWindow::OnConfigure() {
ConfigureDialog configureDialog(this, hotkey_registry);
connect(&configureDialog, &ConfigureDialog::languageChanged, this,
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.