Skip to content
Permalink
Browse files

Core/CheatSearch: Force-enable MMU on memory reads.

  • Loading branch information...
AdmiralCurtiss committed Aug 13, 2019
1 parent 6d6bc71 commit 2472a096f861e789767b7dbcbcb566f0e848c79d
Showing with 12 additions and 43 deletions.
  1. +12 −43 Source/Core/Core/CheatSearch.cpp
@@ -111,31 +111,31 @@ static Cheats::SearchValue ReadValueFromEmulatedMemory(u32 addr, Cheats::DataTyp
{
case Cheats::DataType::U8:
result_value.m_type = Cheats::DataType::U8;
result_value.m_value_u8 = PowerPC::HostRead_U8(addr);
result_value.m_value_u8 = PowerPC::HostRead_U8(addr, true);
break;
case Cheats::DataType::U16:
result_value.m_type = Cheats::DataType::U16;
result_value.m_value_u16 = PowerPC::HostRead_U16(addr);
result_value.m_value_u16 = PowerPC::HostRead_U16(addr, true);
break;
case Cheats::DataType::U32:
result_value.m_type = Cheats::DataType::U32;
result_value.m_value_u32 = PowerPC::HostRead_U32(addr);
result_value.m_value_u32 = PowerPC::HostRead_U32(addr, true);
break;
case Cheats::DataType::F32:
result_value.m_type = Cheats::DataType::F32;
result_value.m_value_f32 = PowerPC::HostRead_F32(addr);
result_value.m_value_f32 = PowerPC::HostRead_F32(addr, true);
break;
case Cheats::DataType::F64:
result_value.m_type = Cheats::DataType::F64;
result_value.m_value_f64 = PowerPC::HostRead_F64(addr);
result_value.m_value_f64 = PowerPC::HostRead_F64(addr, true);
break;
case Cheats::DataType::ByteArray:
{
result_value.m_type = Cheats::DataType::ByteArray;
std::vector<u8> tmp;
tmp.reserve(value_size);
for (size_t i = 0; i < value_size; ++i)
tmp.push_back(PowerPC::HostRead_U8(static_cast<u32>(addr + i)));
tmp.push_back(PowerPC::HostRead_U8(static_cast<u32>(addr + i), true));
result_value.m_value_array = std::move(tmp);
break;
}
@@ -149,13 +149,6 @@ static Cheats::SearchValue ReadValueFromEmulatedMemory(u32 addr, Cheats::DataTyp

constexpr u32 MEMORY_BASE_ADDRESS = 0x80000000;

// sometimes the MMU is off, which causes all memory reads in the 0x80000000 range to fail
// in this case just report a failure instead of returning with zero results and have the user retry
static bool IsCpuInValidState()
{
return PowerPC::HostIsRAMAddress(MEMORY_BASE_ADDRESS);
}

static std::optional<std::vector<Cheats::SearchResult>> NewSearchInternal(
std::function<bool(const Cheats::SearchValue&, const Cheats::SearchValue&)> matches_func,
const Cheats::SearchValue& value, Cheats::DataType type, size_t value_size)
@@ -167,16 +160,11 @@ static std::optional<std::vector<Cheats::SearchResult>> NewSearchInternal(
return std::nullopt;

std::vector<Cheats::SearchResult> results;
bool have_results = false;
Core::RunAsCPUThread([&] {
if (!IsCpuInValidState())
return;

have_results = true;
for (u32 i = 0; i < Memory::REALRAM_SIZE - (value_size - 1); ++i)
{
const u32 addr = MEMORY_BASE_ADDRESS + i;
if (!PowerPC::HostIsRAMAddress(addr))
if (!PowerPC::HostIsRAMAddress(addr, true))
continue;

const auto current_value = ReadValueFromEmulatedMemory(addr, type, value_size);
@@ -189,10 +177,7 @@ static std::optional<std::vector<Cheats::SearchResult>> NewSearchInternal(
}
});

if (have_results)
return results;

return std::nullopt;
return results;
}

std::optional<std::vector<Cheats::SearchResult>> Cheats::NewSearch(DataType type)
@@ -228,16 +213,11 @@ NextSearchInternal(const std::vector<Cheats::SearchResult>& previous_results,
return std::nullopt;

std::vector<Cheats::SearchResult> results;
bool have_results = false;
Core::RunAsCPUThread([&] {
if (!IsCpuInValidState())
return;

have_results = true;
for (const Cheats::SearchResult& previous_result : previous_results)
{
const u32 addr = previous_result.m_address;
if (!PowerPC::HostIsRAMAddress(addr))
if (!PowerPC::HostIsRAMAddress(addr, true))
continue;

const size_t value_size = GetValueSize(previous_result.m_value);
@@ -259,10 +239,7 @@ NextSearchInternal(const std::vector<Cheats::SearchResult>& previous_results,
}
});

if (have_results)
return results;

return std::nullopt;
return results;
}

std::optional<std::vector<Cheats::SearchResult>>
@@ -287,16 +264,11 @@ Cheats::UpdateValues(const std::vector<Cheats::SearchResult>& previous_results)

std::vector<Cheats::SearchResult> results;
results.reserve(previous_results.size());
bool have_results = false;
Core::RunAsCPUThread([&] {
if (!IsCpuInValidState())
return;

have_results = true;
for (const Cheats::SearchResult& previous_result : previous_results)
{
const u32 addr = previous_result.m_address;
if (!PowerPC::HostIsRAMAddress(addr))
if (!PowerPC::HostIsRAMAddress(addr, true))
continue;

const auto current_value = ReadValueFromEmulatedMemory(addr, previous_result.m_value.m_type,
@@ -307,10 +279,7 @@ Cheats::UpdateValues(const std::vector<Cheats::SearchResult>& previous_results)
}
});

if (have_results)
return results;

return std::nullopt;
return results;
}

std::vector<u8> Cheats::GetValueAsByteVector(const Cheats::SearchValue& value)

0 comments on commit 2472a09

Please sign in to comment.
You can’t perform that action at this time.