Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/ui/viewmodels/MemorySearchViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,15 +975,35 @@ std::wstring MemorySearchViewModel::GetTooltip(const SearchResultViewModel& vmRe
return sTooltip;
}

void MemorySearchViewModel::OnCodeNoteChanged(ra::data::ByteAddress nAddress, const std::wstring& sNote)
void MemorySearchViewModel::OnCodeNoteChanged(ra::data::ByteAddress nAddress, const std::wstring&)
{
if (m_vResults.Count() == 0 || m_vSearchResults.empty())
return;

const auto nSize = m_vSearchResults.front()->pResults.GetSize();

const auto& pGameContext = ra::services::ServiceLocator::Get<ra::data::context::GameContext>();
const auto* pCodeNotes = pGameContext.Assets().FindCodeNotes();
if (!pCodeNotes)
return;

const auto* pNote = pCodeNotes->FindCodeNoteModel(nAddress);
if (pNote != nullptr)
{
// if updated note is before first visible result, ignore
if (pNote->GetAddress() + pNote->GetBytes() <= nAddress)
return;

// if updated note is after last visible result, ignore
const auto nBytesForSize = ra::data::Memory::SizeBytes(nSize);
if (pNote->GetAddress() > m_vResults.GetItemAt(m_vResults.Count() - 1)->nAddress + nBytesForSize)
return;
}

for (auto& pRow : m_vResults)
{
if (pRow.nAddress == nAddress)
{
pRow.UpdateCodeNote(sNote);
break;
}
const auto sProcessedNote = pCodeNotes->FindCodeNote(pRow.nAddress, nSize);
pRow.UpdateCodeNote(sProcessedNote);
}
}

Expand Down
57 changes: 56 additions & 1 deletion tests/ui/viewmodels/MemorySearchViewModel_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,6 @@ TEST_CLASS(MemorySearchViewModel_Tests)
Assert::AreEqual(std::wstring(L"Continuous Filter"), search.ContinuousFilterLabel());
}


TEST_METHOD(TestOnCodeNoteChanged)
{
MemorySearchViewModelHarness search;
Expand Down Expand Up @@ -1807,6 +1806,62 @@ TEST_CLASS(MemorySearchViewModel_Tests)
Assert::IsFalse(pRow->bHasCodeNote);
}

TEST_METHOD(TestOnCodeNoteChangedMultiline)
{
MemorySearchViewModelHarness search;
search.InitializeMemory();
search.mockConsoleContext.AddMemoryRegion({ 0U }, { 0xFFU }, ra::data::MemoryRegion::Type::SystemRAM, L"System RAM");
search.BeginNewSearch();
search.mockGameContext.SetCodeNote({ 12U }, L"Summary\n1=A\n2=B");

search.SetComparisonType(ComparisonType::Equals);
search.SetValueType(ra::services::SearchFilterType::Constant);
search.SetFilterValue(L"12");

search.ApplyFilter();

Assert::AreEqual({ 1U }, search.Results().Count());
auto* pRow = search.Results().GetItemAt(0);
Assert::IsNotNull(pRow);
Ensures(pRow != nullptr);

Assert::AreEqual({ 12U }, pRow->nAddress);
Assert::AreEqual(std::wstring(L"Summary"), pRow->GetDescription());
Assert::IsTrue(pRow->bHasCodeNote);

search.mockGameContext.SetCodeNote({ 12U }, L"Summary\n1=C\2=D");
Assert::AreEqual(std::wstring(L"Summary"), pRow->GetDescription());
Assert::IsTrue(pRow->bHasCodeNote);
}

TEST_METHOD(TestOnCodeNoteChangedPartial)
{
MemorySearchViewModelHarness search;
search.InitializeMemory();
search.mockConsoleContext.AddMemoryRegion({ 0U }, { 0xFFU }, ra::data::MemoryRegion::Type::SystemRAM, L"System RAM");
search.BeginNewSearch();
search.mockGameContext.SetCodeNote({ 10U }, L"[4-byte] Summary");

search.SetComparisonType(ComparisonType::Equals);
search.SetValueType(ra::services::SearchFilterType::Constant);
search.SetFilterValue(L"12");

search.ApplyFilter();

Assert::AreEqual({ 1U }, search.Results().Count());
auto* pRow = search.Results().GetItemAt(0);
Assert::IsNotNull(pRow);
Ensures(pRow != nullptr);

Assert::AreEqual({ 12U }, pRow->nAddress);
Assert::AreEqual(std::wstring(L"[4-byte] Summary [3/4]"), pRow->GetDescription());
Assert::IsTrue(pRow->bHasCodeNote);

search.mockGameContext.SetCodeNote({ 10U }, L"[4-byte] Banana");
Assert::AreEqual(std::wstring(L"[4-byte] Banana [3/4]"), pRow->GetDescription());
Assert::IsTrue(pRow->bHasCodeNote);
}

TEST_METHOD(TestScrollDisplaysCurrentValue)
{
MemorySearchViewModelHarness search;
Expand Down
Loading