Merge pull request #12644 from jordan-woyak/ar-multi

DolphinQt: Allow Cheat Search to create multiple AR codes.
This commit is contained in:
Admiral H. Curtiss 2024-03-17 16:26:38 +01:00 committed by GitHub
commit 85dee300b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 24 deletions

View file

@ -498,7 +498,7 @@ void CheatSearchWidget::OnAddressTableContextMenu()
const QString name = QStringLiteral("mem_%1").arg(address, 8, 16, QLatin1Char('0'));
emit RequestWatch(name, address);
});
menu->addAction(tr("Generate Action Replay Code"), this, &CheatSearchWidget::GenerateARCode);
menu->addAction(tr("Generate Action Replay Code(s)"), this, &CheatSearchWidget::GenerateARCodes);
menu->exec(QCursor::pos());
}
@ -521,25 +521,46 @@ void CheatSearchWidget::OnDisplayHexCheckboxStateChanged()
UpdateTableAllCurrentValues(UpdateSource::User);
}
void CheatSearchWidget::GenerateARCode()
void CheatSearchWidget::GenerateARCodes()
{
if (m_address_table->selectedItems().isEmpty())
return;
auto* item = m_address_table->selectedItems()[0];
if (!item)
return;
bool had_success = false;
bool had_error = false;
std::optional<Cheats::GenerateActionReplayCodeErrorCode> error_code;
for (auto* const item : m_address_table->selectedItems())
{
const u32 index = item->data(ADDRESS_TABLE_RESULT_INDEX_ROLE).toUInt();
auto result = Cheats::GenerateActionReplayCode(*m_session, index);
if (result)
{
emit ActionReplayCodeGenerated(*result);
m_info_label_1->setText(tr("Generated AR code."));
had_success = true;
}
else
{
switch (result.Error())
const auto new_error_code = result.Error();
if (!had_error)
{
error_code = new_error_code;
}
else if (error_code != new_error_code)
{
// If we have a different error code signify multiple errors with an empty optional<>.
error_code.reset();
}
had_error = true;
}
}
if (had_error)
{
if (error_code.has_value())
{
switch (*error_code)
{
case Cheats::GenerateActionReplayCodeErrorCode::NotVirtualMemory:
m_info_label_1->setText(tr("Can only generate AR code for values in virtual memory."));
@ -552,6 +573,15 @@ void CheatSearchWidget::GenerateARCode()
break;
}
}
else
{
m_info_label_1->setText(tr("Multiple errors while generating AR codes."));
}
}
else if (had_success)
{
m_info_label_1->setText(tr("Generated AR code(s)."));
}
}
void CheatSearchWidget::RefreshCurrentValueTableItem(

View file

@ -76,7 +76,7 @@ private:
bool UpdateTableRows(const Core::CPUThreadGuard& guard, size_t begin_index, size_t end_index,
UpdateSource source);
void RecreateGUITable();
void GenerateARCode();
void GenerateARCodes();
int GetVisibleRowsBeginIndex() const;
int GetVisibleRowsEndIndex() const;