Skip to content

Commit

Permalink
Qt/CheatsManager: Fix locking defaulting to the value zero
Browse files Browse the repository at this point in the history
  • Loading branch information
spycrab committed Apr 21, 2019
1 parent 05eb916 commit 7013576
Showing 1 changed file with 86 additions and 66 deletions.
152 changes: 86 additions & 66 deletions Source/Core/DolphinQt/CheatsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,84 @@ struct Result
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)
{
setWindowTitle(tr("Cheats Manager"));
Expand Down Expand Up @@ -191,6 +269,8 @@ void CheatsManager::OnMatchContextMenu()

int index = item->data(INDEX_ROLE).toInt();

m_results[index].locked_value = GetResultValue(m_results[index]);

m_watch.push_back(m_results[index]);

Update();
Expand All @@ -199,29 +279,6 @@ void CheatsManager::OnMatchContextMenu()
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()
{
if (!m_ar_code)
Expand All @@ -243,24 +300,6 @@ void CheatsManager::GenerateARCode()
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)
{
if (m_updating)
Expand All @@ -277,6 +316,9 @@ void CheatsManager::OnWatchItemChanged(QTableWidgetItem* item)
case 2:
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]);
break;
case 3:
Expand Down Expand Up @@ -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
{
const auto text = m_match_value->text();
Expand Down Expand Up @@ -517,7 +537,7 @@ void CheatsManager::NextSearch()
Update();
}

static QString GetResultValue(const Result& result)
static QString GetResultString(const Result& result)
{
if (!PowerPC::HostIsRAMAddress(result.address))
{
Expand Down Expand Up @@ -574,7 +594,7 @@ void CheatsManager::Update()
address_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));
value_item->setData(INDEX_ROLE, static_cast<int>(i));
Expand All @@ -593,7 +613,7 @@ void CheatsManager::Update()
auto* lock_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(COLUMN_ROLE, 0);
Expand Down

0 comments on commit 7013576

Please sign in to comment.