Qt/CheatsManager: Fix locking defaulting to the value zero

This commit is contained in:
spycrab
2019-04-21 18:00:36 +02:00
parent 05eb91691c
commit 4f7ff76801

View File

@ -69,6 +69,84 @@ struct Result
u32 locked_value; u32 locked_value;
}; };
static u32 GetResultValue(Result result)
{
switch (result.type)
{
case DataType::Byte:
return PowerPC::HostRead_U8(result.address);
case DataType::Short:
return PowerPC::HostRead_U16(result.address);
case DataType::Int:
return PowerPC::HostRead_U32(result.address);
default:
return 0;
}
}
static void UpdatePatch(Result result)
{
PowerPC::debug_interface.UnsetPatch(result.address);
if (result.locked)
{
switch (result.type)
{
case DataType::Byte:
PowerPC::debug_interface.SetPatch(result.address,
std::vector<u8>{static_cast<u8>(result.locked_value)});
break;
default:
PowerPC::debug_interface.SetPatch(result.address, result.locked_value);
break;
}
}
}
static ActionReplay::AREntry ResultToAREntry(Result result)
{
u8 cmd;
switch (result.type)
{
case DataType::Byte:
cmd = 0x00;
break;
case DataType::Short:
cmd = 0x02;
break;
default:
case DataType::Int:
cmd = 0x04;
break;
}
u32 address = result.address & 0xffffff;
return ActionReplay::AREntry(cmd << 24 | address, result.locked_value);
}
template <typename T>
static bool Compare(T mem_value, T value, CompareType op)
{
switch (op)
{
case CompareType::Equal:
return mem_value == value;
case CompareType::NotEqual:
return mem_value != value;
case CompareType::Less:
return mem_value < value;
case CompareType::LessEqual:
return mem_value <= value;
case CompareType::More:
return mem_value > value;
case CompareType::MoreEqual:
return mem_value >= value;
default:
return false;
}
}
CheatsManager::CheatsManager(QWidget* parent) : QDialog(parent) CheatsManager::CheatsManager(QWidget* parent) : QDialog(parent)
{ {
setWindowTitle(tr("Cheats Manager")); setWindowTitle(tr("Cheats Manager"));
@ -191,6 +269,8 @@ void CheatsManager::OnMatchContextMenu()
int index = item->data(INDEX_ROLE).toInt(); int index = item->data(INDEX_ROLE).toInt();
m_results[index].locked_value = GetResultValue(m_results[index]);
m_watch.push_back(m_results[index]); m_watch.push_back(m_results[index]);
Update(); Update();
@ -199,29 +279,6 @@ void CheatsManager::OnMatchContextMenu()
menu->exec(QCursor::pos()); menu->exec(QCursor::pos());
} }
static ActionReplay::AREntry ResultToAREntry(Result result)
{
u8 cmd;
switch (result.type)
{
case DataType::Byte:
cmd = 0x00;
break;
case DataType::Short:
cmd = 0x02;
break;
default:
case DataType::Int:
cmd = 0x04;
break;
}
u32 address = result.address & 0xffffff;
return ActionReplay::AREntry(cmd << 24 | address, result.locked_value);
}
void CheatsManager::GenerateARCode() void CheatsManager::GenerateARCode()
{ {
if (!m_ar_code) if (!m_ar_code)
@ -243,24 +300,6 @@ void CheatsManager::GenerateARCode()
m_ar_code->AddCode(ar_code); m_ar_code->AddCode(ar_code);
} }
static void UpdatePatch(Result result)
{
PowerPC::debug_interface.UnsetPatch(result.address);
if (result.locked)
{
switch (result.type)
{
case DataType::Byte:
PowerPC::debug_interface.SetPatch(result.address,
std::vector<u8>{static_cast<u8>(result.locked_value)});
break;
default:
PowerPC::debug_interface.SetPatch(result.address, result.locked_value);
break;
}
}
}
void CheatsManager::OnWatchItemChanged(QTableWidgetItem* item) void CheatsManager::OnWatchItemChanged(QTableWidgetItem* item)
{ {
if (m_updating) if (m_updating)
@ -277,6 +316,9 @@ void CheatsManager::OnWatchItemChanged(QTableWidgetItem* item)
case 2: case 2:
m_watch[index].locked = item->checkState() == Qt::Checked; m_watch[index].locked = item->checkState() == Qt::Checked;
if (m_watch[index].locked)
m_watch[index].locked_value = GetResultValue(m_results[index]);
UpdatePatch(m_watch[index]); UpdatePatch(m_watch[index]);
break; break;
case 3: case 3:
@ -408,28 +450,6 @@ size_t CheatsManager::GetTypeSize() const
} }
} }
template <typename T>
static bool Compare(T mem_value, T value, CompareType op)
{
switch (op)
{
case CompareType::Equal:
return mem_value == value;
case CompareType::NotEqual:
return mem_value != value;
case CompareType::Less:
return mem_value < value;
case CompareType::LessEqual:
return mem_value <= value;
case CompareType::More:
return mem_value > value;
case CompareType::MoreEqual:
return mem_value >= value;
default:
return false;
}
}
bool CheatsManager::MatchesSearch(u32 addr) const bool CheatsManager::MatchesSearch(u32 addr) const
{ {
const auto text = m_match_value->text(); const auto text = m_match_value->text();
@ -517,7 +537,7 @@ void CheatsManager::NextSearch()
Update(); Update();
} }
static QString GetResultValue(const Result& result) static QString GetResultString(const Result& result)
{ {
if (!PowerPC::HostIsRAMAddress(result.address)) if (!PowerPC::HostIsRAMAddress(result.address))
{ {
@ -537,6 +557,9 @@ static QString GetResultValue(const Result& result)
return QString::number(PowerPC::HostRead_F64(result.address)); return QString::number(PowerPC::HostRead_F64(result.address));
case DataType::String: case DataType::String:
return QObject::tr("String Match"); return QObject::tr("String Match");
default:
// Make MSVC happy
return QStringLiteral("");
} }
} }
@ -574,7 +597,7 @@ void CheatsManager::Update()
address_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); address_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
value_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); value_item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
value_item->setText(GetResultValue(m_results[i])); value_item->setText(GetResultString(m_results[i]));
address_item->setData(INDEX_ROLE, static_cast<int>(i)); address_item->setData(INDEX_ROLE, static_cast<int>(i));
value_item->setData(INDEX_ROLE, static_cast<int>(i)); value_item->setData(INDEX_ROLE, static_cast<int>(i));
@ -593,7 +616,7 @@ void CheatsManager::Update()
auto* lock_item = new QTableWidgetItem; auto* lock_item = new QTableWidgetItem;
auto* value_item = new QTableWidgetItem; auto* value_item = new QTableWidgetItem;
value_item->setText(GetResultValue(m_results[i])); value_item->setText(GetResultString(m_results[i]));
name_item->setData(INDEX_ROLE, static_cast<int>(i)); name_item->setData(INDEX_ROLE, static_cast<int>(i));
name_item->setData(COLUMN_ROLE, 0); name_item->setData(COLUMN_ROLE, 0);