diff --git a/lib/libimhex/include/hex/helpers/debugging.hpp b/lib/libimhex/include/hex/helpers/debugging.hpp index 2778a623d..5605cbb63 100644 --- a/lib/libimhex/include/hex/helpers/debugging.hpp +++ b/lib/libimhex/include/hex/helpers/debugging.hpp @@ -44,4 +44,7 @@ namespace hex::dbg { } } + bool debugModeEnabled(); + void setDebugModeEnabled(bool enabled); + } \ No newline at end of file diff --git a/lib/libimhex/source/helpers/debugging.cpp b/lib/libimhex/source/helpers/debugging.cpp index d996866f2..50115f49d 100644 --- a/lib/libimhex/source/helpers/debugging.cpp +++ b/lib/libimhex/source/helpers/debugging.cpp @@ -12,4 +12,13 @@ namespace hex::dbg { } + static bool s_debugMode = false; + bool debugModeEnabled() { + return s_debugMode; + } + + void setDebugModeEnabled(bool enabled) { + s_debugMode = enabled; + } + } \ No newline at end of file diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index 8058afbd5..4260b9597 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -297,7 +298,25 @@ namespace hex::plugin::builtin { return hex::format("hex.builtin.command.cmd.result"_lang, input.data()); }, [](auto input) { - hex::executeCommand(input); + if (input.starts_with("imhex ")) { + // Handle ImHex internal commands + auto command = input.substr(6); + auto parts = splitConversionCommandInput(command); + if (!parts.empty()) { + if (parts.size() == 2 && parts[0] == "debug") { + if (parts[1] == "on") { + ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.debug_mode_enabled", true); + ui::ToastInfo::open("Debug mode enabled!"); + } else if (parts[1] == "off") { + ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.debug_mode_enabled", false); + ui::ToastInfo::open("Debug mode disabled!"); + } + } + } + } else { + hex::executeCommand(input); + } + return std::nullopt; }); diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index 6728bc824..a6cac0f7e 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -23,7 +23,7 @@ namespace hex::plugin::builtin { void addTitleBarButtons() { - #if defined(DEBUG) + if (dbg::debugModeEnabled()) { ContentRegistry::Interface::addTitleBarButton(ICON_VS_DEBUG, "hex.builtin.title_bar_button.debug_build", []{ if (ImGui::GetIO().KeyShift) { RequestOpenPopup::post("DebugMenu"); @@ -31,7 +31,7 @@ namespace hex::plugin::builtin { hex::openWebpage("https://imhex.werwolv.net/debug"); } }); - #endif + } ContentRegistry::Interface::addTitleBarButton(ICON_VS_SMILEY, "hex.builtin.title_bar_button.feedback", []{ hex::openWebpage("https://github.com/WerWolv/ImHex/discussions/categories/feedback"); @@ -50,89 +50,85 @@ namespace hex::plugin::builtin { } } - #if defined(DEBUG) + static void drawDebugPopup() { + static bool showImGuiDemo = false; + static bool showImPlotDemo = false; + static bool showImPlot3DDemo = false; - static void drawDebugPopup() { - static bool showImGuiDemo = false; - static bool showImPlotDemo = false; - static bool showImPlot3DDemo = false; + ImGui::SetNextWindowSize(scaled({ 300, 150 }), ImGuiCond_Always); + if (ImGui::BeginPopup("DebugMenu")) { + if (ImGui::BeginTabBar("DebugTabBar")) { + if (ImGui::BeginTabItem("ImHex")) { + if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { + ImGui::Checkbox("Show Debug Variables", &dbg::impl::getDebugWindowState()); - ImGui::SetNextWindowSize(scaled({ 300, 150 }), ImGuiCond_Always); - if (ImGui::BeginPopup("DebugMenu")) { - if (ImGui::BeginTabBar("DebugTabBar")) { - if (ImGui::BeginTabItem("ImHex")) { - if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { - ImGui::Checkbox("Show Debug Variables", &dbg::impl::getDebugWindowState()); - - ImGuiExt::Header("Information"); - ImGuiExt::TextFormatted("Running Tasks: {0}", TaskManager::getRunningTaskCount()); - ImGuiExt::TextFormatted("Running Background Tasks: {0}", TaskManager::getRunningBackgroundTaskCount()); - ImGuiExt::TextFormatted("Last Frame Time: {0:.3f}ms", ImHexApi::System::getLastFrameTime() * 1000.0F); - } - ImGui::EndChild(); - - ImGui::EndTabItem(); + ImGuiExt::Header("Information"); + ImGuiExt::TextFormatted("Running Tasks: {0}", TaskManager::getRunningTaskCount()); + ImGuiExt::TextFormatted("Running Background Tasks: {0}", TaskManager::getRunningBackgroundTaskCount()); + ImGuiExt::TextFormatted("Last Frame Time: {0:.3f}ms", ImHexApi::System::getLastFrameTime() * 1000.0F); } - if (ImGui::BeginTabItem("ImGui")) { - if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { - auto ctx = ImGui::GetCurrentContext(); - ImGui::Checkbox("Show ImGui Demo", &showImGuiDemo); - ImGui::Checkbox("Show ImPlot Demo", &showImPlotDemo); - ImGui::Checkbox("Show ImPlot3D Demo", &showImPlot3DDemo); + ImGui::EndChild(); - if (ImGui::Button("Trigger Breakpoint in Item") || ctx->DebugItemPickerActive) - ImGui::DebugStartItemPicker(); - } - ImGui::EndChild(); - - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Crashes")) { - if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { - if (ImGui::Button("Throw Exception")) { - TaskManager::doLater([] { - throw std::runtime_error("Test exception"); - }); - } - if (ImGui::Button("Access Invalid Memory")) { - TaskManager::doLater([] { - *reinterpret_cast(0x10) = 0x10; - std::unreachable(); - }); - } - if (ImGui::Button("Raise SIGSEGV")) { - TaskManager::doLater([] { - raise(SIGSEGV); - }); - } - if (ImGui::Button("Corrupt Memory")) { - TaskManager::doLater([] { - auto bytes = new u8[0xFFFFF]; - - delete[] bytes; - delete[] bytes; - }); - } - } - ImGui::EndChild(); - - ImGui::EndTabItem(); - } - - ImGui::EndTabBar(); + ImGui::EndTabItem(); } - ImGui::EndPopup(); - } + if (ImGui::BeginTabItem("ImGui")) { + if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { + auto ctx = ImGui::GetCurrentContext(); + ImGui::Checkbox("Show ImGui Demo", &showImGuiDemo); + ImGui::Checkbox("Show ImPlot Demo", &showImPlotDemo); + ImGui::Checkbox("Show ImPlot3D Demo", &showImPlot3DDemo); - if (showImGuiDemo) - ImGui::ShowDemoWindow(&showImGuiDemo); - if (showImPlotDemo) - ImPlot::ShowDemoWindow(&showImPlotDemo); - if (showImPlot3DDemo) - ImPlot3D::ShowDemoWindow(&showImPlot3DDemo); + if (ImGui::Button("Trigger Breakpoint in Item") || ctx->DebugItemPickerActive) + ImGui::DebugStartItemPicker(); + } + ImGui::EndChild(); + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Crashes")) { + if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { + if (ImGui::Button("Throw Exception")) { + TaskManager::doLater([] { + throw std::runtime_error("Test exception"); + }); + } + if (ImGui::Button("Access Invalid Memory")) { + TaskManager::doLater([] { + *reinterpret_cast(0x10) = 0x10; + std::unreachable(); + }); + } + if (ImGui::Button("Raise SIGSEGV")) { + TaskManager::doLater([] { + raise(SIGSEGV); + }); + } + if (ImGui::Button("Corrupt Memory")) { + TaskManager::doLater([] { + auto bytes = new u8[0xFFFFF]; + + delete[] bytes; + delete[] bytes; + }); + } + } + ImGui::EndChild(); + + ImGui::EndTabItem(); + } + + ImGui::EndTabBar(); + } + ImGui::EndPopup(); } - #endif + if (showImGuiDemo) + ImGui::ShowDemoWindow(&showImGuiDemo); + if (showImPlotDemo) + ImPlot::ShowDemoWindow(&showImPlotDemo); + if (showImPlot3DDemo) + ImPlot3D::ShowDemoWindow(&showImPlot3DDemo); + } static bool s_drawDragDropOverlay = false; static void drawDragNDropOverlay() { @@ -178,9 +174,9 @@ namespace hex::plugin::builtin { EventFrameEnd::subscribe(drawGlobalPopups); EventFrameEnd::subscribe(drawDragNDropOverlay); - #if defined(DEBUG) + if (dbg::debugModeEnabled()) { EventFrameEnd::subscribe(drawDebugPopup); - #endif + } EventFileDragged::subscribe([](bool entered) { s_drawDragDropOverlay = entered; @@ -196,7 +192,7 @@ namespace hex::plugin::builtin { }); } - #if defined(DEBUG) + if (dbg::debugModeEnabled()) { ContentRegistry::Interface::addFooterItem([] { static float framerate = 0; if (ImGuiExt::HasSecondPassed()) { @@ -237,7 +233,7 @@ namespace hex::plugin::builtin { ImGui::PopStyleVar(); } }); - #endif + } ContentRegistry::Interface::addFooterItem([] { static bool shouldResetProgress = false; diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index 1537fb98a..39f57e445 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -135,5 +136,9 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") { // Show a warning banner on debug builds #if defined(DEBUG) ui::BannerIcon::open(ICON_VS_ERROR, "You're running a Debug build of ImHex. Performance will be degraded!", ImColor(153, 58, 58)); + dbg::setDebugModeEnabled(true); + #else + const auto enabled = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.debug_mode_enabled", false); + dbg::setDebugModeEnabled(enabled); #endif }