CheatSearchTab: Make the search results list auto update address values

This commit is contained in:
Lioncash 2015-08-07 10:04:28 -04:00
parent 40818c4aad
commit 00a4184893
2 changed files with 86 additions and 55 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm>
#include <array> #include <array>
#include <cstring> #include <cstring>
#include <wx/button.h> #include <wx/button.h>
@ -13,6 +14,7 @@
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/stattext.h> #include <wx/stattext.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/timer.h>
#include "Common/CommonFuncs.h" #include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -32,6 +34,9 @@ namespace
CheatSearchTab::CheatSearchTab(wxWindow* const parent) CheatSearchTab::CheatSearchTab(wxWindow* const parent)
: wxPanel(parent) : wxPanel(parent)
{ {
m_update_timer.SetOwner(this);
Bind(wxEVT_TIMER, &CheatSearchTab::OnTimerUpdate, this);
// first scan button // first scan button
m_btn_init_scan = new wxButton(this, wxID_ANY, _("New Scan")); m_btn_init_scan = new wxButton(this, wxID_ANY, _("New Scan"));
m_btn_init_scan->Bind(wxEVT_BUTTON, &CheatSearchTab::StartNewSearch, this); m_btn_init_scan->Bind(wxEVT_BUTTON, &CheatSearchTab::StartNewSearch, this);
@ -208,23 +213,7 @@ void CheatSearchTab::FilterCheatSearchResults(wxCommandEvent&)
return; return;
} }
user_x_val = (u32)parsed_x_val; user_x_val = SwapValue(static_cast<u32>(parsed_x_val));
// #ifdef LIL_ENDIAN :p
switch (m_search_type_size)
{
case 1:
break;
case 2:
*(u16*)&user_x_val = Common::swap16((u8*)&user_x_val);
break;
case 4:
user_x_val = Common::swap32(user_x_val);
break;
}
// #elseif BIG_ENDIAN
// would have to move <u32 vals (8/16bit) to start of the user_x_val for the comparisons i use below
// #endif
} }
for (CheatSearchResult& result : m_search_results) for (CheatSearchResult& result : m_search_results)
@ -251,14 +240,48 @@ void CheatSearchTab::FilterCheatSearchResults(wxCommandEvent&)
UpdateCheatSearchResultsList(); UpdateCheatSearchResultsList();
} }
void CheatSearchTab::CreateARCode(wxCommandEvent&)
{
long idx = m_lview_search_results->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (idx == wxNOT_FOUND)
return;
const u32 address = m_search_results[idx].address | ((m_search_type_size & ~1) << 24);
CreateCodeDialog arcode_dlg(this, address, ActionReplay::GetARCodes());
arcode_dlg.SetExtraStyle(arcode_dlg.GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS);
arcode_dlg.ShowModal();
}
void CheatSearchTab::ApplyFocus(wxFocusEvent& ev) void CheatSearchTab::ApplyFocus(wxFocusEvent& ev)
{ {
ev.Skip(); ev.Skip();
m_value_x_radiobtn.rad_uservalue->SetValue(true); m_value_x_radiobtn.rad_uservalue->SetValue(true);
} }
void CheatSearchTab::OnTimerUpdate(wxTimerEvent&)
{
if (Core::GetState() != Core::CORE_RUN)
return;
// Only update the currently visible list rows.
long first = m_lview_search_results->GetTopItem();
long last = std::min(m_lview_search_results->GetItemCount(), m_lview_search_results->GetCountPerPage());
m_lview_search_results->Freeze();
while (first < last)
{
UpdateCheatSearchResultItem(first);
first++;
}
m_lview_search_results->Thaw();
}
void CheatSearchTab::UpdateCheatSearchResultsList() void CheatSearchTab::UpdateCheatSearchResultsList()
{ {
m_update_timer.Stop();
m_lview_search_results->ClearAll(); m_lview_search_results->ClearAll();
ResetListViewColumns(); ResetListViewColumns();
@ -274,25 +297,31 @@ void CheatSearchTab::UpdateCheatSearchResultsList()
for (size_t i = 0; i < m_search_results.size(); i++) for (size_t i = 0; i < m_search_results.size(); i++)
{ {
u32 display_value = m_search_results[i].old_value; // Insert into the list control.
wxString address_string = wxString::Format("0x%08X", m_search_results[i].address);
long index = m_lview_search_results->InsertItem(static_cast<long>(i), address_string);
switch (m_search_type_size) UpdateCheatSearchResultItem(index);
{
case 1:
break;
case 2:
*(u16*)&display_value = Common::swap16((u8*)&display_value);
break;
case 4:
display_value = Common::swap32(display_value);
break;
} }
// Insert into the list control. m_lview_search_results->Thaw();
wxString buf;
buf.Printf("0x%08X", m_search_results[i].address);
long index = m_lview_search_results->InsertItem(static_cast<long>(i), buf);
// Half-second update interval
m_update_timer.Start(500);
}
m_label_results_count->SetLabel(count_label);
}
void CheatSearchTab::UpdateCheatSearchResultItem(long index)
{
u32 address_value = 0;
std::memcpy(&address_value, &Memory::m_pRAM[m_search_results[index].address], m_search_type_size);
m_search_results[index].old_value = address_value;
u32 display_value = SwapValue(address_value);
wxString buf;
buf.Printf("0x%08X", display_value); buf.Printf("0x%08X", display_value);
m_lview_search_results->SetItem(index, 1, buf); m_lview_search_results->SetItem(index, 1, buf);
@ -305,26 +334,6 @@ void CheatSearchTab::UpdateCheatSearchResultsList()
std::memcpy(&display_value_double, &display_value, sizeof(u32)); std::memcpy(&display_value_double, &display_value, sizeof(u32));
buf.Printf("%e", display_value_double); buf.Printf("%e", display_value_double);
m_lview_search_results->SetItem(index, 3, buf); m_lview_search_results->SetItem(index, 3, buf);
}
m_lview_search_results->Thaw();
}
m_label_results_count->SetLabel(count_label);
}
void CheatSearchTab::CreateARCode(wxCommandEvent&)
{
long idx = m_lview_search_results->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (idx != wxNOT_FOUND)
{
const u32 address = m_search_results[idx].address | ((m_search_type_size & ~1) << 24);
CreateCodeDialog arcode_dlg(this, address, ActionReplay::GetARCodes());
arcode_dlg.SetExtraStyle(arcode_dlg.GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS);
arcode_dlg.ShowModal();
}
} }
void CheatSearchTab::ResetListViewColumns() void CheatSearchTab::ResetListViewColumns()
@ -334,3 +343,18 @@ void CheatSearchTab::ResetListViewColumns()
m_lview_search_results->AppendColumn(_("Value (float)")); m_lview_search_results->AppendColumn(_("Value (float)"));
m_lview_search_results->AppendColumn(_("Value (double)")); m_lview_search_results->AppendColumn(_("Value (double)"));
} }
u32 CheatSearchTab::SwapValue(u32 value) const
{
switch (m_search_type_size)
{
case 2:
*(u16*)&value = Common::swap16((u8*)&value);
break;
case 4:
value = Common::swap32(value);
break;
}
return value;
}

View File

@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/timer.h>
class wxButton; class wxButton;
class wxChoice; class wxChoice;
@ -32,11 +33,15 @@ private:
}; };
void UpdateCheatSearchResultsList(); void UpdateCheatSearchResultsList();
void UpdateCheatSearchResultItem(long index);
void ResetListViewColumns(); void ResetListViewColumns();
u32 SwapValue(u32 value) const;
void StartNewSearch(wxCommandEvent& event); void StartNewSearch(wxCommandEvent& event);
void FilterCheatSearchResults(wxCommandEvent& event); void FilterCheatSearchResults(wxCommandEvent& event);
void CreateARCode(wxCommandEvent&); void CreateARCode(wxCommandEvent&);
void ApplyFocus(wxFocusEvent&); void ApplyFocus(wxFocusEvent&);
void OnTimerUpdate(wxTimerEvent&);
std::vector<CheatSearchResult> m_search_results; std::vector<CheatSearchResult> m_search_results;
unsigned int m_search_type_size; unsigned int m_search_type_size;
@ -51,6 +56,8 @@ private:
wxRadioBox* m_data_sizes; wxRadioBox* m_data_sizes;
wxTimer m_update_timer;
struct struct
{ {
wxRadioButton* rad_oldvalue; wxRadioButton* rad_oldvalue;