diff --git a/rpcs3/rpcs3qt/debugger_frame.cpp b/rpcs3/rpcs3qt/debugger_frame.cpp index 4769c99f18..b529e38359 100644 --- a/rpcs3/rpcs3qt/debugger_frame.cpp +++ b/rpcs3/rpcs3qt/debugger_frame.cpp @@ -435,7 +435,7 @@ void debugger_frame::keyPressEvent(QKeyEvent* event) dlg.set_input_font(mono, false); dlg.set_clear_button_enabled(false); dlg.set_button_enabled(QDialogButtonBox::StandardButton::Ok, false); - dlg.set_validator(new QRegularExpressionValidator(QRegularExpression("^[1-9][0-9]*$"))); + dlg.set_validator(new QRegularExpressionValidator(QRegularExpression("^[1-9][0-9]*$"), &dlg)); u32 max = 0; @@ -1188,11 +1188,11 @@ void debugger_frame::ShowGotoAddressDialog() if (const auto thread = get_cpu(); !thread || thread->id_type() != 2) { - expression_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"))); + expression_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"), this)); } else { - expression_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,5}$"))); + expression_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,5}$"), this)); } // Ok/Cancel diff --git a/rpcs3/rpcs3qt/elf_memory_dumping_dialog.cpp b/rpcs3/rpcs3qt/elf_memory_dumping_dialog.cpp index 7bbcc53689..0eb7f41844 100644 --- a/rpcs3/rpcs3qt/elf_memory_dumping_dialog.cpp +++ b/rpcs3/rpcs3qt/elf_memory_dumping_dialog.cpp @@ -34,13 +34,13 @@ elf_memory_dumping_dialog::elf_memory_dumping_dialog(u32 ppu_debugger_addr, std: m_seg_list->setMinimumWidth(gui::utils::get_label_width(tr("PPU Address: 0x00000000, LS Address: 0x00000, Segment Size: 0x00000, Flags: 0x0"))); // Address expression input - auto make_hex_edit = [mono](u32 max_digits) + auto make_hex_edit = [this, mono](u32 max_digits) { QLineEdit* le = new QLineEdit(); le->setFont(mono); le->setMaxLength(max_digits + 2); le->setPlaceholderText("0x" + QStringLiteral("0").repeated(max_digits)); - le->setValidator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^(0[xX])?0*[a-fA-F0-9]{0,%1}$").arg(max_digits)))); + le->setValidator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^(0[xX])?0*[a-fA-F0-9]{0,%1}$").arg(max_digits)), this)); return le; }; diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 50fa5c81b6..d8f9e15f8c 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -1633,7 +1633,7 @@ void main_window::DecryptSPRXLibraries() dlg->set_input_font(mono, true, '0'); dlg->set_clear_button_enabled(false); dlg->set_button_enabled(QDialogButtonBox::StandardButton::Ok, false); - dlg->set_validator(new QRegularExpressionValidator(QRegularExpression("^((((((K?L)?I)?C)?=)?0)?x)?[a-fA-F0-9]{0,32}$"))); // HEX only (with additional KLIC=0x prefix for convenience) + dlg->set_validator(new QRegularExpressionValidator(QRegularExpression("^((((((K?L)?I)?C)?=)?0)?x)?[a-fA-F0-9]{0,32}$"), this)); // HEX only (with additional KLIC=0x prefix for convenience) dlg->setAttribute(Qt::WA_DeleteOnClose); connect(dlg, &input_dialog::text_changed, dlg, [dlg](const QString& text) diff --git a/rpcs3/rpcs3qt/memory_viewer_panel.cpp b/rpcs3/rpcs3qt/memory_viewer_panel.cpp index 07a7ff9bd2..f8ee6fcebe 100644 --- a/rpcs3/rpcs3qt/memory_viewer_panel.cpp +++ b/rpcs3/rpcs3qt/memory_viewer_panel.cpp @@ -92,7 +92,7 @@ memory_viewer_panel::memory_viewer_panel(QWidget* parent, std::shared_ptrsetMaxLength(18); m_addr_line->setFixedWidth(75); m_addr_line->setFocus(); - m_addr_line->setValidator(new QRegularExpressionValidator(QRegularExpression(m_type == thread_type::spu ? "^(0[xX])?0*[a-fA-F0-9]{0,5}$" : "^(0[xX])?0*[a-fA-F0-9]{0,8}$"))); + m_addr_line->setValidator(new QRegularExpressionValidator(QRegularExpression(m_type == thread_type::spu ? "^(0[xX])?0*[a-fA-F0-9]{0,5}$" : "^(0[xX])?0*[a-fA-F0-9]{0,8}$"), this)); hbox_tools_mem_addr->addWidget(m_addr_line); tools_mem_addr->setLayout(hbox_tools_mem_addr); diff --git a/rpcs3/rpcs3qt/patch_creator_dialog.cpp b/rpcs3/rpcs3qt/patch_creator_dialog.cpp index ed4cd0450a..de71ac5115 100644 --- a/rpcs3/rpcs3qt/patch_creator_dialog.cpp +++ b/rpcs3/rpcs3qt/patch_creator_dialog.cpp @@ -31,11 +31,15 @@ patch_creator_dialog::patch_creator_dialog(QWidget* parent) , mMonoFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)) , mValidColor(gui::utils::get_label_color("log_level_success")) , mInvalidColor(gui::utils::get_label_color("log_level_error")) + , m_offset_validator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?[a-fA-F0-9]{0,8}$"), this)) { ui->setupUi(this); ui->patchEdit->setFont(mMonoFont); ui->addPatchOffsetEdit->setFont(mMonoFont); + ui->addPatchOffsetEdit->setClearButtonEnabled(true); ui->addPatchValueEdit->setFont(mMonoFont); + ui->addPatchValueEdit->setClearButtonEnabled(true); + ui->addPatchCommentEdit->setClearButtonEnabled(true); ui->instructionTable->setFont(mMonoFont); ui->instructionTable->setItemDelegate(new table_item_delegate(this, false)); ui->instructionTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::Fixed); @@ -66,6 +70,8 @@ patch_creator_dialog::patch_creator_dialog(QWidget* parent) connect(ui->addPatchButton, &QAbstractButton::clicked, this, [this]() { add_instruction(ui->instructionTable->rowCount()); }); init_patch_type_bombo_box(ui->addPatchTypeComboBox, patch_type::be32, false); + connect(ui->addPatchTypeComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int index){ update_validator(index, ui->addPatchTypeComboBox, ui->addPatchOffsetEdit); }); + update_validator(ui->addPatchTypeComboBox->currentIndex(), ui->addPatchTypeComboBox, ui->addPatchOffsetEdit); generate_yml(); } @@ -198,6 +204,25 @@ void patch_creator_dialog::show_table_menu(const QPoint& pos) menu.exec(ui->instructionTable->viewport()->mapToGlobal(pos)); } +void patch_creator_dialog::update_validator(int index, QComboBox* combo_box, QLineEdit* line_edit) +{ + if (index < 0 || !combo_box || !line_edit || !combo_box->itemData(index).canConvert()) + { + return; + } + + switch (combo_box->itemData(index).value()) + { + case patch_type::move_file: + case patch_type::hide_file: + line_edit->setValidator(nullptr); + break; + default: + line_edit->setValidator(m_offset_validator); + break; + } +} + void patch_creator_dialog::add_instruction(int row) { const QString type = ui->addPatchTypeComboBox->currentText(); @@ -206,6 +231,25 @@ void patch_creator_dialog::add_instruction(int row) const QString comment = ui->addPatchCommentEdit->text(); const patch_type t = patch_engine::get_patch_type(type.toStdString()); + + switch (t) + { + case patch_type::move_file: + case patch_type::hide_file: + break; + default: + { + int pos = 0; + QString text_to_validate = offset; + if (m_offset_validator->validate(text_to_validate, pos) == QValidator::Invalid) + { + QMessageBox::information(this, tr("Offset invalid!"), tr("The patch offset is invalid.\nThe offset has to be a hexadecimal number with 8 digits at most.")); + return; + } + break; + } + } + QComboBox* combo_box = create_patch_type_bombo_box(t); ui->instructionTable->insertRow(std::max(0, std::min(row, ui->instructionTable->rowCount()))); diff --git a/rpcs3/rpcs3qt/patch_creator_dialog.h b/rpcs3/rpcs3qt/patch_creator_dialog.h index 435fd73454..d8ddf120cb 100644 --- a/rpcs3/rpcs3qt/patch_creator_dialog.h +++ b/rpcs3/rpcs3qt/patch_creator_dialog.h @@ -25,6 +25,7 @@ private: QColor mValidColor; QColor mInvalidColor; bool m_valid = true; // Will be invalidated immediately + QRegularExpressionValidator* m_offset_validator = nullptr; enum class move_direction { @@ -40,6 +41,8 @@ private: static void init_patch_type_bombo_box(QComboBox* combo_box, patch_type set_type, bool searchable); QComboBox* create_patch_type_bombo_box(patch_type set_type); + void update_validator(int index, QComboBox* combo_box, QLineEdit* line_edit); + private Q_SLOTS: void show_table_menu(const QPoint& pos); void validate(); diff --git a/rpcs3/rpcs3qt/rsx_debugger.cpp b/rpcs3/rpcs3qt/rsx_debugger.cpp index 5e962a8bc3..5d269d2761 100644 --- a/rpcs3/rpcs3qt/rsx_debugger.cpp +++ b/rpcs3/rpcs3qt/rsx_debugger.cpp @@ -166,7 +166,7 @@ rsx_debugger::rsx_debugger(std::shared_ptr gui_settings, QWidget* tex_idx_line->setMaxLength(18); tex_idx_line->setFixedWidth(75); tex_idx_line->setFocus(); - tex_idx_line->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"))); + tex_idx_line->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"), this)); QLineEdit* tex_fmt_override_line = new QLineEdit(this); tex_fmt_override_line->setPlaceholderText("00"); @@ -174,7 +174,7 @@ rsx_debugger::rsx_debugger(std::shared_ptr gui_settings, QWidget* tex_fmt_override_line->setMaxLength(18); tex_fmt_override_line->setFixedWidth(75); tex_fmt_override_line->setFocus(); - tex_fmt_override_line->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,2}$"))); + tex_fmt_override_line->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,2}$"), this)); hbox_idx_line->addWidget(tex_idx_line); hbox_idx_line->addWidget(tex_fmt_override_line); diff --git a/rpcs3/rpcs3qt/system_cmd_dialog.cpp b/rpcs3/rpcs3qt/system_cmd_dialog.cpp index 45dfbdb0e0..fb2b19a838 100644 --- a/rpcs3/rpcs3qt/system_cmd_dialog.cpp +++ b/rpcs3/rpcs3qt/system_cmd_dialog.cpp @@ -33,13 +33,13 @@ system_cmd_dialog::system_cmd_dialog(QWidget* parent) m_value_input = new QLineEdit(); m_value_input->setFont(mono); m_value_input->setMaxLength(18); - m_value_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"))); + m_value_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"), this)); m_value_input->setPlaceholderText(QString("0x%1").arg(0, 16, 16, QChar('0'))); m_custom_command_input = new QLineEdit(); m_custom_command_input->setFont(mono); m_custom_command_input->setMaxLength(18); - m_custom_command_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"))); + m_custom_command_input->setValidator(new QRegularExpressionValidator(QRegularExpression("^(0[xX])?0*[a-fA-F0-9]{0,8}$"), this)); m_custom_command_input->setPlaceholderText(QString("0x%1").arg(0, 16, 16, QChar('0'))); m_command_box = new QComboBox(); diff --git a/rpcs3/rpcs3qt/vfs_dialog_usb_input.cpp b/rpcs3/rpcs3qt/vfs_dialog_usb_input.cpp index 7015fab090..b39a89c011 100644 --- a/rpcs3/rpcs3qt/vfs_dialog_usb_input.cpp +++ b/rpcs3/rpcs3qt/vfs_dialog_usb_input.cpp @@ -58,12 +58,12 @@ vfs_dialog_usb_input::vfs_dialog_usb_input(const QString& name, const cfg::devic m_vid_edit = new QLineEdit; m_vid_edit->setMaxLength(4); - m_vid_edit->setValidator(new QRegularExpressionValidator(QRegularExpression("^[a-fA-F0-9]*$"))); // HEX only + m_vid_edit->setValidator(new QRegularExpressionValidator(QRegularExpression("^[a-fA-F0-9]*$"), this)); // HEX only m_vid_edit->setText(QString::fromStdString(info->vid)); m_pid_edit = new QLineEdit; m_pid_edit->setMaxLength(4); - m_pid_edit->setValidator(new QRegularExpressionValidator(QRegularExpression("^[a-fA-F0-9]*$"))); // HEX only + m_pid_edit->setValidator(new QRegularExpressionValidator(QRegularExpression("^[a-fA-F0-9]*$"), this)); // HEX only m_pid_edit->setText(QString::fromStdString(info->pid)); m_serial_edit = new QLineEdit;