20 std::string searchExpr;
22 ImGui::SetNextWindowSize(
gl::vec2{35, 0} * ImGui::GetFontSize(), ImGuiCond_FirstUseEver);
24 const auto& style = ImGui::GetStyle();
27 auto height = 12.5f * ImGui::GetTextLineHeightWithSpacing();
28 auto sWidth = 2.0f * (style.WindowBorderSize + style.WindowPadding.x)
29 + style.IndentSpacing + 6 * tSize + 5 * bSpacing;
30 im::Child(
"search", {sWidth, height}, ImGuiChildFlags_Borders, [&]{
32 HelpMarker(
"OpenMSX cheat finder. See here for a quick tutorial:\n"
33 " openMSX tutorial: Working with the Cheat Finder\n"
34 " http://www.youtube.com/watch?v=F11ltfkCtKo\n"
35 "The UI has changed, but the ideas remain the same.");
37 ImGui::TextUnformatted(
"Compare"sv);
39 auto bSize = ImVec2{tSize, 0.0f};
40 if (ImGui::Button(
"<", bSize)) searchExpr =
"$new < $old";
41 simpleToolTip(
"Search for memory locations with strictly decreased value");
42 ImGui::SameLine(0.0f, bSpacing);
43 if (ImGui::Button(
"<=", bSize)) searchExpr =
"$new <= $old";
44 simpleToolTip(
"Search for memory locations with decreased value");
45 ImGui::SameLine(0.0f, bSpacing);
46 if (ImGui::Button(
"!=", bSize)) searchExpr =
"$new != $old";
47 simpleToolTip(
"Search for memory locations with changed value");
48 ImGui::SameLine(0.0f, bSpacing);
49 if (ImGui::Button(
"==", bSize)) searchExpr =
"$new == $old";
50 simpleToolTip(
"Search for memory locations with unchanged value");
51 ImGui::SameLine(0.0f, bSpacing);
52 if (ImGui::Button(
">=", bSize)) searchExpr =
"$new >= $old";
53 simpleToolTip(
"Search for memory locations with increased value");
54 ImGui::SameLine(0.0f, bSpacing);
55 if (ImGui::Button(
">", bSize)) searchExpr =
"$new > $old";
56 simpleToolTip(
"Search for memory locations with strictly increased value");
60 ImGui::SetNextItemWidth(3 * ImGui::GetFontSize());
61 ImGui::InputScalar(
"##value", ImGuiDataType_U8, &searchValue);
63 if (ImGui::Button(
"Go")) {
64 searchExpr =
strCat(
"$new == ", searchValue);
66 simpleToolTip(
"Search for memory locations with a specific value");
69 start |= ImGui::Button(
"Restart search");
73 im::Child(
"result", {0.0f, height}, ImGuiChildFlags_Borders, [&]{
74 auto num = searchResults.size();
77 start |= ImGui::Button(
"Start a new search");
82 ImGui::Text(
"Results: %d remaining locations", narrow<int>(num));
84 int flags = ImGuiTableFlags_RowBg |
85 ImGuiTableFlags_BordersV |
86 ImGuiTableFlags_BordersOuter |
87 ImGuiTableFlags_ScrollY;
89 ImGui::TableSetupScrollFreeze(0, 1);
90 ImGui::TableSetupColumn(
"Address");
91 ImGui::TableSetupColumn(
"Previous");
92 ImGui::TableSetupColumn(
"New value");
93 ImGui::TableHeadersRow();
95 for (
const auto& row : searchResults) {
96 if (ImGui::TableNextColumn()) {
97 ImGui::Text(
"0x%04x", row.address);
99 if (ImGui::TableNextColumn()) {
100 ImGui::Text(
"%d", row.oldValue);
102 if (ImGui::TableNextColumn()) {
103 ImGui::Text(
"%d", row.newValue);
112 manager.execute(
TclObject(
"cheat_finder::start"));
115 if (!searchExpr.empty()) {
116 auto result = manager.execute(
makeTclList(
"cheat_finder::search", searchExpr)).value_or(TclObject{});
118 auto line = result.getListIndexUnchecked(narrow<unsigned>(i));
119 auto addr = line.getListIndexUnchecked(0).getOptionalInt().value_or(0);
120 auto oldValue = line.getListIndexUnchecked(1).getOptionalInt().value_or(0);
121 auto newValue = line.getListIndexUnchecked(2).getOptionalInt().value_or(0);
122 return SearchResult{narrow_cast<uint16_t>(addr),
123 narrow_cast<uint8_t>(oldValue),
124 narrow_cast<uint8_t>(newValue)};
void Table(const char *str_id, int column, ImGuiTableFlags flags, const ImVec2 &outer_size, float inner_width, std::invocable<> auto next)