From 085afc0dabcd46904adbc7af25a280daebec43be Mon Sep 17 00:00:00 2001 From: xcasadio Date: Sun, 18 May 2025 11:01:32 +0200 Subject: [PATCH 1/2] fix input scalar in typed debugger window --- src/gui/widgets/typed_debugger.cc | 54 ++++++++++++++++--------------- src/gui/widgets/typed_debugger.h | 4 +-- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/gui/widgets/typed_debugger.cc b/src/gui/widgets/typed_debugger.cc index cbadc1e2c..e49c86262 100644 --- a/src/gui/widgets/typed_debugger.cc +++ b/src/gui/widgets/typed_debugger.cc @@ -490,10 +490,7 @@ void PCSX::Widgets::TypedDebugger::displayNode(WatchTreeNode* node, const uint32 printValue(nodeType, node->size, value); ImGui::TableNextColumn(); // New value. memFile->wSeek(startAddress, SEEK_SET); - displayNewValueInput(nodeType, node->size, value, memFile); - ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]); - ImGui::TextUnformatted("--"); - ImGui::PopStyleColor(); + displayNewValueInput(nodeType, node->size, value, memFile, currentAddress); ImGui::TableNextColumn(); // Breakpoints. if (watchView) { displayBreakpointOptions(node, currentAddress); @@ -551,56 +548,61 @@ void PCSX::Widgets::TypedDebugger::printValue(const char* type, size_t type_size // Make an input widget for the value at the given address of the given type. If // type is not a known primitive, it'll try to allow editing of the value // anyway. -void PCSX::Widgets::TypedDebugger::displayNewValueInput(const char* type, size_t type_size, Slice value, - IO memFile) { - static char s[64]; +void PCSX::Widgets::TypedDebugger::displayNewValueInput(const char* type, size_t type_size, const Slice& value, + IO& memFile, uint32_t address) { static const int8_t step = 1; static const int8_t stepFast = 100; const auto signedFormat = m_hex ? "%x" : "%d"; const auto unsignedFormat = m_hex ? "%x" : "%u"; const auto inputFlags = m_hex ? ImGuiInputTextFlags_CharsHexadecimal : ImGuiInputTextFlags_CharsDecimal; - const uint32_t address = memFile->rTell(); switch (type_size) { case 1: if (equals(type, "char")) { - if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_S8, &m_newValue, - &step, &stepFast, signedFormat, inputFlags)) { - memFile->write(m_newValue); + m_newValues[address] = *value.data(); + if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_S8, + &m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) { + memFile->write(m_newValues[address]); } } else { // We have a uchar or something of size 1. - if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_U8, &m_newValue, - &step, &stepFast, unsignedFormat, inputFlags)) { - memFile->write(m_newValue); + + m_newValues[address] = *value.data(); + if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_U8, + &m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) { + memFile->write(m_newValues[address]); } } break; case 2: if (equals(type, "short")) { - if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_S16, - &m_newValue, &step, &stepFast, signedFormat, inputFlags)) { - memFile->write(m_newValue); + m_newValues[address] = *value.data(); + if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_S16, + &m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) { + memFile->write(m_newValues[address]); } } else { // We have a ushort or something of size 2. - if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_U16, - &m_newValue, &step, &stepFast, unsignedFormat, inputFlags)) { - memFile->write(m_newValue); + m_newValues[address] = *value.data(); + if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_U16, + &m_newValues[address], &step, &stepFast, unsignedFormat, inputFlags)) { + memFile->write(m_newValues[address]); } } break; case 4: if (equals(type, "int") || equals(type, "long")) { - if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_S32, - &m_newValue, &step, &stepFast, signedFormat, inputFlags)) { - memFile->write(m_newValue); + m_newValues[address] = *value.data(); + if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_S32, + &m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) { + memFile->write(m_newValues[address]); } } else { // We have uint or something of size 4. - if (ImGui::InputScalar(fmt::format(f_("New value##{}"), address).c_str(), ImGuiDataType_U32, - &m_newValue, &step, &stepFast, unsignedFormat, inputFlags)) { - memFile->write(m_newValue); + m_newValues[address] = *value.data(); + if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_U32, + &m_newValues[address], &step, &stepFast, unsignedFormat, inputFlags)) { + memFile->write(m_newValues[address]); } } break; diff --git a/src/gui/widgets/typed_debugger.h b/src/gui/widgets/typed_debugger.h index 390aa429a..eb7027d15 100644 --- a/src/gui/widgets/typed_debugger.h +++ b/src/gui/widgets/typed_debugger.h @@ -119,7 +119,7 @@ class TypedDebugger { std::vector m_watchBreakpoints; std::unordered_map> m_disabledInstructions; bool m_hex = false; - uint32_t m_newValue = 0; + std::unordered_map m_newValues; /** * Functions. @@ -156,7 +156,7 @@ class TypedDebugger { uint32_t extraImGuiId = 0); void printValue(const char* type, size_t type_size, void* value); void printValue(const char* type, size_t type_size, Slice value); - void displayNewValueInput(const char* type, size_t size_type, Slice value, IO memFile); + void displayNewValueInput(const char* type, size_t size_type, const Slice& value, IO& memFile, uint32_t address); void displayBreakpointOptions(WatchTreeNode* node, const uint32_t address); /** From 41a85beb1b903526fc625644ebc4acb0e14f0d9a Mon Sep 17 00:00:00 2001 From: xcasadio Date: Tue, 27 May 2025 09:41:02 +0200 Subject: [PATCH 2/2] fix input scalar in typed debugger window --- src/gui/widgets/typed_debugger.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/typed_debugger.cc b/src/gui/widgets/typed_debugger.cc index e49c86262..319aaefe8 100644 --- a/src/gui/widgets/typed_debugger.cc +++ b/src/gui/widgets/typed_debugger.cc @@ -569,7 +569,7 @@ void PCSX::Widgets::TypedDebugger::displayNewValueInput(const char* type, size_t m_newValues[address] = *value.data(); if (ImGui::InputScalar(fmt::format(f_("##{}"), address).c_str(), ImGuiDataType_U8, - &m_newValues[address], &step, &stepFast, signedFormat, inputFlags)) { + &m_newValues[address], &step, &stepFast, unsignedFormat, inputFlags)) { memFile->write(m_newValues[address]); } }