diff --git a/lib/external/pattern_language b/lib/external/pattern_language index c7bca89b1aaf4..8909b964e24e6 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit c7bca89b1aaf4bb942c53bc3561af687eca44667 +Subproject commit 8909b964e24e63b37840d469db5746371e295a33 diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 39e0442f68a66..29a1fb24b1868 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -438,7 +438,7 @@ namespace hex { namespace impl { - using VisualizerFunctionCallback = std::function)>; + using VisualizerFunctionCallback = std::function)>; struct FunctionDefinition { pl::api::Namespace ns; diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 78e1b877d894a..5e27102a858d9 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -172,17 +172,22 @@ namespace hex { } void Window::fullFrame() { - static u32 crashWatchdog = 0; + [[maybe_unused]] static u32 crashWatchdog = 0; if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) { return; } + #if !defined(DEBUG) try { + #endif + + // Render an entire frame this->frameBegin(); this->frame(); this->frameEnd(); + #if !defined(DEBUG) // Feed the watchdog crashWatchdog = 0; } catch (...) { @@ -202,6 +207,7 @@ namespace hex { // Handle the exception handleException(); } + #endif } void Window::loop() { diff --git a/plugins/builtin/source/content/pl_visualizers.cpp b/plugins/builtin/source/content/pl_visualizers.cpp index 498771be86f3f..f6cbefc070350 100644 --- a/plugins/builtin/source/content/pl_visualizers.cpp +++ b/plugins/builtin/source/content/pl_visualizers.cpp @@ -5,8 +5,8 @@ namespace hex::plugin::builtin { - void drawHexVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawChunkBasedEntropyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); + void drawHexVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawChunkBasedEntropyVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); void registerPatternLanguageVisualizers() { using ParamCount = pl::api::FunctionParameterCount; diff --git a/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp b/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp index 6bb1aa76471ff..a77d9fd8672d0 100644 --- a/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp +++ b/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp @@ -8,7 +8,7 @@ namespace hex::plugin::builtin { - void drawChunkBasedEntropyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawChunkBasedEntropyVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { // Variable used to store the result to avoid having to recalculate the result at each frame static DiagramChunkBasedEntropyAnalysis analyzer; diff --git a/plugins/builtin/source/content/pl_visualizers/hex_viewer.cpp b/plugins/builtin/source/content/pl_visualizers/hex_viewer.cpp index eb07a54d5de4c..fc0ad8c254d42 100644 --- a/plugins/builtin/source/content/pl_visualizers/hex_viewer.cpp +++ b/plugins/builtin/source/content/pl_visualizers/hex_viewer.cpp @@ -12,7 +12,7 @@ namespace hex::plugin::builtin { - void drawHexVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawHexVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static ui::HexEditor editor; static prv::MemoryProvider dataProvider; diff --git a/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp b/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp index adbb737c6d677..021320ff04da1 100644 --- a/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp +++ b/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp @@ -12,7 +12,7 @@ namespace hex::plugin::disasm { - void drawDisassemblyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawDisassemblyVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { struct Disassembly { u64 address; std::vector bytes; diff --git a/plugins/disassembler/source/plugin_disassembler.cpp b/plugins/disassembler/source/plugin_disassembler.cpp index c81f0d3b1077a..2392ca15ef76d 100644 --- a/plugins/disassembler/source/plugin_disassembler.cpp +++ b/plugins/disassembler/source/plugin_disassembler.cpp @@ -14,7 +14,7 @@ using namespace hex::plugin::disasm; namespace hex::plugin::disasm { - void drawDisassemblyVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); + void drawDisassemblyVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); } diff --git a/plugins/ui/include/ui/pattern_drawer.hpp b/plugins/ui/include/ui/pattern_drawer.hpp index c6b7819b58d52..189293b0e5e7d 100644 --- a/plugins/ui/include/ui/pattern_drawer.hpp +++ b/plugins/ui/include/ui/pattern_drawer.hpp @@ -71,7 +71,7 @@ namespace hex::ui { void makeSelectable(const pl::ptrn::Pattern &pattern); void drawValueColumn(pl::ptrn::Pattern& pattern); - void drawVisualizer(const std::map &visualizers, const std::vector &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &iterable, bool reset); + void drawVisualizer(const std::map &visualizers, const std::vector &arguments, pl::ptrn::Pattern &pattern, bool reset); void drawFavoriteColumn(const pl::ptrn::Pattern& pattern); bool drawNameColumn(const pl::ptrn::Pattern &pattern, bool leaf = false); void drawColorColumn(const pl::ptrn::Pattern& pattern); diff --git a/plugins/ui/source/ui/pattern_drawer.cpp b/plugins/ui/source/ui/pattern_drawer.cpp index ebf823125e710..3ac1c59e20ead 100644 --- a/plugins/ui/source/ui/pattern_drawer.cpp +++ b/plugins/ui/source/ui/pattern_drawer.cpp @@ -50,7 +50,7 @@ namespace hex::ui { if (!currSelection.has_value()) return false; - return Region{ address, size }.overlaps(*currSelection); + return Region(address, size).overlaps(*currSelection); } bool isPatternFullySelected(u64 address, u64 size) { @@ -113,7 +113,7 @@ namespace hex::ui { ImGui::TableNextColumn(); const auto bitSize = (pattern.getBitOffsetForDisplay() + pattern.getBitSize() - (pattern.getSize() == 0 ? 0 : 1)); - ImGuiExt::TextFormatted("0x{0:08X}.{1}", pattern.getOffset() + bitSize / 8, bitSize % 8); + ImGuiExt::TextFormatted("0x{0:08X}.{1}", pattern.getOffset() + (bitSize / 8), bitSize % 8); } } @@ -339,7 +339,7 @@ namespace hex::ui { ImGui::TextUnformatted(pattern.getComment().c_str()); } - void PatternDrawer::drawVisualizer(const std::map &visualizers, const std::vector &arguments, pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &iterable, bool reset) { + void PatternDrawer::drawVisualizer(const std::map &visualizers, const std::vector &arguments, pl::ptrn::Pattern &pattern, bool reset) { auto visualizerName = arguments.front().toString(true); if (auto entry = visualizers.find(visualizerName); entry != visualizers.end()) { @@ -350,7 +350,7 @@ namespace hex::ui { if (paramCount >= minParams && paramCount <= maxParams) { try { - visualizer.callback(pattern, iterable, reset, { arguments.begin() + 1, arguments.end() }); + visualizer.callback(pattern, reset, { arguments.begin() + 1, arguments.end() }); } catch (std::exception &e) { m_lastVisualizerError = e.what(); } @@ -383,13 +383,13 @@ namespace hex::ui { bool shouldReset = false; if (ImGui::Button(hex::format(" {} {}", ICON_VS_EYE_WATCH, value).c_str(), ImVec2(width, ImGui::GetTextLineHeight()))) { auto previousPattern = m_currVisualizedPattern; - m_currVisualizedPattern = &pattern; - m_lastVisualizerError.clear(); - if (m_currVisualizedPattern != previousPattern) + if (!m_lastVisualizerError.empty() || m_currVisualizedPattern != previousPattern) shouldReset = true; + m_lastVisualizerError.clear(); + ImGui::OpenPopup("Visualizer"); } ImGui::PopStyleVar(2); @@ -398,14 +398,14 @@ namespace hex::ui { if (ImGui::BeginPopup("Visualizer")) { if (m_currVisualizedPattern == &pattern) { - drawVisualizer(ContentRegistry::PatternLanguage::impl::getVisualizers(), visualizeArgs, pattern, dynamic_cast(pattern), !m_visualizedPatterns.contains(&pattern) || shouldReset); + drawVisualizer(ContentRegistry::PatternLanguage::impl::getVisualizers(), visualizeArgs, pattern, !m_visualizedPatterns.contains(&pattern) || shouldReset); m_visualizedPatterns.insert(&pattern); } ImGui::EndPopup(); } } else if (const auto &inlineVisualizeArgs = pattern.getAttributeArguments("hex::inline_visualize"); !inlineVisualizeArgs.empty()) { - drawVisualizer(ContentRegistry::PatternLanguage::impl::getInlineVisualizers(), inlineVisualizeArgs, pattern, dynamic_cast(pattern), true); + drawVisualizer(ContentRegistry::PatternLanguage::impl::getInlineVisualizers(), inlineVisualizeArgs, pattern, true); } else { ImGuiExt::TextFormatted("{}", value); } @@ -1239,7 +1239,7 @@ namespace hex::ui { this->resetEditing(); } - ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGui::GetTextLineHeightWithSpacing() * 9.4F); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - (ImGui::GetTextLineHeightWithSpacing() * 9.4F)); if (ImGuiExt::InputTextIcon("##Search", ICON_VS_FILTER, m_filterText)) { m_filter = parseRValueFilter(m_filterText).value_or(Filter{ }); updateFilter(); @@ -1284,7 +1284,7 @@ namespace hex::ui { const auto &extension = formatter->getFileExtension(); if (ImGui::MenuItem(name.c_str())) { - fs::openFileBrowser(fs::DialogMode::Save, { { name, extension } }, [&](const std::fs::path &path) { + fs::openFileBrowser(fs::DialogMode::Save, { fs::ItemFilter(name, extension) }, [&](const std::fs::path &path) { auto result = formatter->format(*runtime); wolv::io::File output(path, wolv::io::File::Mode::Create); diff --git a/plugins/visualizers/source/content/pl_inline_visualizers.cpp b/plugins/visualizers/source/content/pl_inline_visualizers.cpp index 71da4b37f3d43..cc8258f01f011 100644 --- a/plugins/visualizers/source/content/pl_inline_visualizers.cpp +++ b/plugins/visualizers/source/content/pl_inline_visualizers.cpp @@ -12,7 +12,7 @@ namespace hex::plugin::visualizers { namespace { - void drawColorInlineVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments) { + void drawColorInlineVisualizer(pl::ptrn::Pattern &, bool, std::span arguments) { auto r = arguments[0].toFloatingPoint(); auto g = arguments[1].toFloatingPoint(); auto b = arguments[2].toFloatingPoint(); @@ -21,7 +21,7 @@ namespace hex::plugin::visualizers { ImGui::ColorButton("color", ImVec4(r / 255.0F, g / 255.0F, b / 255.0F, a / 255.0F), ImGuiColorEditFlags_NoTooltip, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight())); } - void drawGaugeInlineVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments) { + void drawGaugeInlineVisualizer(pl::ptrn::Pattern &, bool, std::span arguments) { auto value = arguments[0].toFloatingPoint(); const auto color = ImGui::GetStyleColorVec4(ImGuiCol_Text); @@ -37,7 +37,7 @@ namespace hex::plugin::visualizers { ImGui::PopStyleColor(3); } - void drawButtonInlineVisualizer(pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &, bool, std::span arguments) { + void drawButtonInlineVisualizer(pl::ptrn::Pattern &pattern, bool, std::span arguments) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0, 0.5F)); diff --git a/plugins/visualizers/source/content/pl_visualizers.cpp b/plugins/visualizers/source/content/pl_visualizers.cpp index d25bf66c4a881..d938979b3c718 100644 --- a/plugins/visualizers/source/content/pl_visualizers.cpp +++ b/plugins/visualizers/source/content/pl_visualizers.cpp @@ -5,16 +5,16 @@ namespace hex::plugin::visualizers { - void drawLinePlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawScatterPlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawImageVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawBitmapVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void draw3DVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawSoundVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawCoordinateVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawTimestampVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawTableVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); - void drawDigitalSignalVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments); + void drawLinePlotVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawScatterPlotVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawImageVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawBitmapVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void draw3DVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawSoundVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawCoordinateVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawTimestampVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawTableVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); + void drawDigitalSignalVisualizer(pl::ptrn::Pattern &, bool, std::span arguments); void registerPatternLanguageVisualizers() { using ParamCount = pl::api::FunctionParameterCount; diff --git a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp index b0a495c8be6ac..3e958b54768ce 100644 --- a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -9,7 +10,6 @@ #include #include #include -#include #include @@ -23,7 +23,7 @@ namespace hex::plugin::visualizers { namespace { - enum class IndexType { + enum class IndexType : u8 { U8, U16, U32, @@ -105,15 +105,15 @@ namespace hex::plugin::visualizers { u32 vertexCount = vertexIndices.size() / 3; indices.resize(vertexCount * 6); - for (u32 i = 0; i < vertexCount; ++i) { + for (u32 i = 0; i < vertexCount; i += 1) { indices[i * 6] = vertexIndices[3 * i]; - indices[i * 6 + 1] = vertexIndices[3 * i + 1]; + indices[(i * 6) + 1] = vertexIndices[(3 * i) + 1]; - indices[i * 6 + 2] = vertexIndices[3 * i + 1]; - indices[i * 6 + 3] = vertexIndices[3 * i + 2]; + indices[(i * 6) + 2] = vertexIndices[(3 * i) + 1]; + indices[(i * 6) + 3] = vertexIndices[(3 * i) + 2]; - indices[i * 6 + 4] = vertexIndices[3 * i + 2]; - indices[i * 6 + 5] = vertexIndices[3 * i]; + indices[(i * 6) + 4] = vertexIndices[(3 * i) + 2]; + indices[(i * 6) + 5] = vertexIndices[3 * i]; } vertexIndices.resize(indices.size()); @@ -125,13 +125,13 @@ namespace hex::plugin::visualizers { float getBoundingBox(const std::vector &vertices) { gl::Vector minWorld(std::numeric_limits::infinity()), maxWorld(-std::numeric_limits::infinity()); for (u32 i = 0; i < vertices.size(); i += 3) { - if (vertices[i] < minWorld[0]) minWorld[0] = vertices[i]; - if (vertices[i + 1] < minWorld[1]) minWorld[1] = vertices[i + 1]; - if (vertices[i + 2] < minWorld[2]) minWorld[2] = vertices[i + 2]; + minWorld[0] = std::min(vertices[i], minWorld[0]); + minWorld[1] = std::min(vertices[i + 1], minWorld[1]); + minWorld[2] = std::min(vertices[i + 2], minWorld[2]); - if (vertices[i] > maxWorld[0]) maxWorld[0] = vertices[i]; - if (vertices[i + 1] > maxWorld[1]) maxWorld[1] = vertices[i + 1]; - if (vertices[i + 2] > maxWorld[2]) maxWorld[2] = vertices[i + 2]; + maxWorld[0] = std::max(vertices[i], maxWorld[0]); + maxWorld[1] = std::max(vertices[i + 1], maxWorld[1]); + maxWorld[2] = std::max(vertices[i + 2], maxWorld[2]); } minWorld[3] = 1; @@ -200,23 +200,23 @@ namespace hex::plugin::visualizers { auto idx1 = indices[i + 1]; auto idx2 = indices[i + 2]; - auto v1 = gl::Vector({vertices[3 * idx], vertices[3 * idx + 1], vertices[3 * idx + 2]}); + auto v1 = gl::Vector({vertices[3 * idx], vertices[(3 * idx) + 1], vertices[(3 * idx) + 2]}); auto v2 = gl::Vector( - {vertices[3 * idx1], vertices[3 * idx1 + 1], vertices[3 * idx1 + 2]}); + {vertices[3 * idx1], vertices[(3 * idx1) + 1], vertices[(3 * idx1) + 2]}); auto v3 = gl::Vector( - {vertices[3 * idx2], vertices[3 * idx2 + 1], vertices[3 * idx2 + 2]}); + {vertices[3 * idx2], vertices[(3 * idx2) + 1], vertices[(3 * idx2) + 2]}); auto weighted = ((v2 - v1).cross(v3 - v1)); normals[3 * idx] += weighted[0]; - normals[3 * idx + 1] += weighted[1]; - normals[3 * idx + 2] += weighted[2]; - normals[3 * idx1] += weighted[0]; - normals[3 * idx1 + 1] += weighted[1]; - normals[3 * idx1 + 2] += weighted[2]; - normals[3 * idx2] += weighted[0]; - normals[3 * idx2 + 1] += weighted[1]; - normals[3 * idx2 + 2] += weighted[2]; + normals[(3 * idx) + 1] += weighted[1]; + normals[(3 * idx) + 2] += weighted[2]; + normals[(3 * idx1)] += weighted[0]; + normals[(3 * idx1) + 1] += weighted[1]; + normals[(3 * idx1) + 2] += weighted[2]; + normals[(3 * idx2)] += weighted[0]; + normals[(3 * idx2) + 1] += weighted[1]; + normals[(3 * idx2) + 2] += weighted[2]; } for (u32 i = 0; i < normals.size(); i += 3) { @@ -271,6 +271,7 @@ namespace hex::plugin::visualizers { } void loadLineVectors(LineVectors &lineVectors, IndexType indexType) { + const auto vertexCount = lineVectors.vertices.size(); s_max = getBoundingBox(lineVectors.vertices); if (lineVectors.colors.empty()) @@ -283,11 +284,21 @@ namespace hex::plugin::visualizers { indicesForLines(lineVectors.indices16); else indicesForLines(lineVectors.indices32); + + const auto isIndexInRange = [vertexCount](auto index) { return index >= vertexCount; }; + + if ( + !std::ranges::all_of(lineVectors.indices8, isIndexInRange) || + !std::ranges::all_of(lineVectors.indices16, isIndexInRange) || + !std::ranges::all_of(lineVectors.indices32, isIndexInRange) + ) { + throw std::logic_error("One or more indices point to out-of-range vertex"); + } } - void processKeyEvent(ImGuiKey key, float &variable, float incr, float accel) { + void processKeyEvent(ImGuiKey key, float &variable, float increment, float acceleration) { if (ImGui::IsKeyPressed(key)) { - auto temp = variable + incr * accel; + auto temp = variable + (increment * acceleration); if (variable * temp < 0.0F) variable = 0.0F; else @@ -320,8 +331,7 @@ namespace hex::plugin::visualizers { auto scrollDelta = ImGui::GetIO().MouseWheel; scaling += scrollDelta * 0.1F * accel; - if (scaling < 0.01F) - scaling = 0.01F; + scaling = std::max(scaling, 0.01F); processKeyEvent(ImGuiKey_Keypad4, translation[0], -0.1F, accel); processKeyEvent(ImGuiKey_Keypad6, translation[0], 0.1F, accel); @@ -339,7 +349,7 @@ namespace hex::plugin::visualizers { processKeyEvent(ImGuiKey_KeypadAdd, rotation[2], -0.075F, accel); processKeyEvent(ImGuiKey_KeypadSubtract, rotation[2], 0.075F, accel); - rotation[2] = std::fmod(rotation[2], 2 * std::numbers::pi); + rotation[2] = std::fmod(rotation[2], 2 * std::numbers::pi_v); } @@ -577,7 +587,7 @@ namespace hex::plugin::visualizers { } - void draw3DVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void draw3DVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static gl::LightSourceVectors sourceVectors(20); static gl::VertexArray sourceVertexArray = {}; static gl::LightSourceBuffers sourceBuffers(sourceVertexArray, sourceVectors); @@ -598,7 +608,7 @@ namespace hex::plugin::visualizers { std::shared_ptr indicesPattern = arguments[1].toPattern(); std::shared_ptr normalsPattern = nullptr; std::shared_ptr colorsPattern = nullptr; - std::shared_ptr uvPattern1 = nullptr; + std::shared_ptr uv1Pattern = nullptr; std::string textureFile; if (arguments.size() > 2) { @@ -606,7 +616,7 @@ namespace hex::plugin::visualizers { if (arguments.size() > 3) { colorsPattern = arguments[3].toPattern(); if (arguments.size() > 4) { - uvPattern1 = arguments[4].toPattern(); + uv1Pattern = arguments[4].toPattern(); if (arguments.size() > 5) textureFile = arguments[5].toString(); } @@ -618,7 +628,7 @@ namespace hex::plugin::visualizers { const auto fontSize = ImGui::GetFontSize(); const auto framePad = ImGui::GetStyle().FramePadding; - float minSize = fontSize * 8_scaled + framePad.x * 20_scaled; + float minSize = (fontSize * 8_scaled) + (framePad.x * 20_scaled); minSize = minSize > 200_scaled ? minSize : 200_scaled; if (s_renderingWindowSize.x <= 0 || s_renderingWindowSize.y <= 0) @@ -629,10 +639,8 @@ namespace hex::plugin::visualizers { else s_drawTexture = false; - if (s_renderingWindowSize.x < minSize) - s_renderingWindowSize.x = minSize; - if (s_renderingWindowSize.y < minSize) - s_renderingWindowSize.y = minSize; + s_renderingWindowSize.x = std::max(s_renderingWindowSize.x, minSize); + s_renderingWindowSize.y = std::max(s_renderingWindowSize.y, minSize); gl::Matrix mvp(0); @@ -670,8 +678,8 @@ namespace hex::plugin::visualizers { vectors.colors = patternToArray(colorsPattern.get()); if (normalsPattern != nullptr) vectors.normals = patternToArray(normalsPattern.get()); - if (uvPattern1 != nullptr) - vectors.uv1 = patternToArray(uvPattern1.get()); + if (uv1Pattern != nullptr) + vectors.uv1 = patternToArray(uv1Pattern.get()); loadVectors(vectors, s_indexType); @@ -731,12 +739,12 @@ namespace hex::plugin::visualizers { float viewHeight = s_renderingWindowSize.y / 500.0F; glViewport(0,0 , GLsizei(renderTexture.getWidth()), GLsizei(renderTexture.getHeight())); glDepthRangef(s_nearLimit, s_farLimit); - glClearColor(0.00F, 0.00F, 0.00F, 0.00f); + glClearColor(0.00F, 0.00F, 0.00F, 0.00F); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); - if (s_isPerspective == 0) { + if (!s_isPerspective) { projection = gl::GetOrthographicMatrix(viewWidth, viewHeight, s_nearLimit, s_farLimit, false); totalScale = s_scaling / (std::fabs(s_translation[2])); scale(0, 0) = totalScale; @@ -768,8 +776,11 @@ namespace hex::plugin::visualizers { mvp = model * view * projection; if (s_drawMode == GL_TRIANGLES) { - static gl::Shader shader = gl::Shader(romfs::get("shaders/default/vertex.glsl").string(), - romfs::get("shaders/default/fragment.glsl").string()); + static gl::Shader shader = gl::Shader( + romfs::get("shaders/default/vertex.glsl").string(), + romfs::get("shaders/default/fragment.glsl").string() + ); + shader.bind(); shader.setUniform("modelScale", scaledModel); @@ -819,8 +830,10 @@ namespace hex::plugin::visualizers { } } else { static gl::Shader lineShader = gl::Shader( - romfs::get("shaders/default/lineVertex.glsl").string(), - romfs::get("shaders/default/lineFragment.glsl").string()); + romfs::get("shaders/default/lineVertex.glsl").string(), + romfs::get("shaders/default/lineFragment.glsl").string() + ); + lineShader.bind(); lineShader.setUniform("modelMatrix", scaledModel); lineShader.setUniform("viewMatrix", view); @@ -853,8 +866,10 @@ namespace hex::plugin::visualizers { if (s_drawGrid || s_drawAxes) { static auto gridAxesShader = gl::Shader( - romfs::get("shaders/default/lineVertex.glsl").string(), - romfs::get("shaders/default/lineFragment.glsl").string()); + romfs::get("shaders/default/lineVertex.glsl").string(), + romfs::get("shaders/default/lineFragment.glsl").string() + ); + gridAxesShader.bind(); gridAxesShader.setUniform("modelMatrix", model); @@ -880,8 +895,9 @@ namespace hex::plugin::visualizers { } if (s_drawLightSource) { static auto sourceShader = gl::Shader( - romfs::get("shaders/default/lightVertex.glsl").string(), - romfs::get("shaders/default/lightFragment.glsl").string()); + romfs::get("shaders/default/lightVertex.glsl").string(), + romfs::get("shaders/default/lightFragment.glsl").string() + ); sourceShader.bind(); sourceShader.setUniform("modelMatrix", model); diff --git a/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp b/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp index 1dd2b4523a587..11f974b015a97 100644 --- a/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp @@ -13,7 +13,7 @@ namespace hex::plugin::visualizers { - void drawCoordinateVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawCoordinateVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static ImVec2 coordinate; static double latitude, longitude; static std::string address; diff --git a/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp b/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp index 409eb2a604cc2..0d727017b756f 100644 --- a/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/digital_signal.cpp @@ -4,15 +4,14 @@ #include #include -#include #include #include namespace hex::plugin::visualizers { - void drawDigitalSignalVisualizer(pl::ptrn::Pattern &pattern, pl::ptrn::IIterable &iterable, bool shouldReset, std::span) { - auto *bitfield = dynamic_cast(&pattern); + void drawDigitalSignalVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { + auto *bitfield = dynamic_cast(arguments[0].toPattern().get()); if (bitfield == nullptr) throw std::logic_error("Digital signal visualizer only works with bitfields."); @@ -30,8 +29,8 @@ namespace hex::plugin::visualizers { dataPoints.clear(); lastPoint = { 0, 0 }; - iterable.forEachEntry(0, iterable.getEntryCount(), [&](u64, pl::ptrn::Pattern *entry) { - size_t bitSize = 0; + bitfield->forEachEntry(0, bitfield->getEntryCount(), [&](u64, pl::ptrn::Pattern *entry) { + size_t bitSize; if (auto bitfieldField = dynamic_cast(entry); bitfieldField != nullptr) bitSize = bitfieldField->getBitSize(); else @@ -47,7 +46,7 @@ namespace hex::plugin::visualizers { ); lastPoint = dataPoints.back().points[1]; - lastPoint.x += bitSize; + lastPoint.x += float(bitSize); }); dataPoints.push_back({ @@ -70,7 +69,7 @@ namespace hex::plugin::visualizers { const auto &right = dataPoints[i + 1]; { - auto x = left.points[1].x + (right.points[0].x - left.points[1].x) / 2; + auto x = left.points[1].x + ((right.points[0].x - left.points[1].x) / 2); ImPlot::Annotation(x, 0.55F, left.color, {}, false, "%s", left.label.c_str()); ImPlot::Annotation(x, 0.40F, left.color, {}, false, "%s", left.value.c_str()); } diff --git a/plugins/visualizers/source/content/pl_visualizers/image.cpp b/plugins/visualizers/source/content/pl_visualizers/image.cpp index 8ebf38a58cf9b..0784ac67e2580 100644 --- a/plugins/visualizers/source/content/pl_visualizers/image.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/image.cpp @@ -8,7 +8,7 @@ namespace hex::plugin::visualizers { - void drawImageVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawImageVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static ImGuiExt::Texture texture; static float scale = 1.0F; @@ -32,7 +32,7 @@ namespace hex::plugin::visualizers { } } - void drawBitmapVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawBitmapVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static ImGuiExt::Texture texture; static float scale = 1.0F; diff --git a/plugins/visualizers/source/content/pl_visualizers/line_plot.cpp b/plugins/visualizers/source/content/pl_visualizers/line_plot.cpp index a754cc54b8b25..978e41267e0b6 100644 --- a/plugins/visualizers/source/content/pl_visualizers/line_plot.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/line_plot.cpp @@ -9,7 +9,7 @@ namespace hex::plugin::visualizers { - void drawLinePlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawLinePlotVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static std::vector values; auto dataPattern = arguments[0].toPattern(); diff --git a/plugins/visualizers/source/content/pl_visualizers/scatter_plot.cpp b/plugins/visualizers/source/content/pl_visualizers/scatter_plot.cpp index fcc2130961814..9439dfc8cab0e 100644 --- a/plugins/visualizers/source/content/pl_visualizers/scatter_plot.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/scatter_plot.cpp @@ -9,7 +9,7 @@ namespace hex::plugin::visualizers { - void drawScatterPlotVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawScatterPlotVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static std::vector xValues, yValues; auto xPattern = arguments[0].toPattern(); diff --git a/plugins/visualizers/source/content/pl_visualizers/sound.cpp b/plugins/visualizers/source/content/pl_visualizers/sound.cpp index 4806f9744b922..be4ca10d7b1f2 100644 --- a/plugins/visualizers/source/content/pl_visualizers/sound.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/sound.cpp @@ -12,7 +12,7 @@ namespace hex::plugin::visualizers { - void drawSoundVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawSoundVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { auto wavePattern = arguments[0].toPattern(); auto channels = arguments[1].toUnsigned(); auto sampleRate = arguments[2].toUnsigned(); diff --git a/plugins/visualizers/source/content/pl_visualizers/table.cpp b/plugins/visualizers/source/content/pl_visualizers/table.cpp index afea6a5c677c5..8a06336e33c5c 100644 --- a/plugins/visualizers/source/content/pl_visualizers/table.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/table.cpp @@ -13,7 +13,7 @@ namespace hex::plugin::visualizers { - void drawTableVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool shouldReset, std::span arguments) { + void drawTableVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static std::vector tableContent; static u128 width = 0, height = 0; @@ -47,7 +47,7 @@ namespace hex::plugin::visualizers { for (u128 j = 0; j < width; j += 1) { ImGui::TableSetColumnIndex(j); if (i * width + j < tableContent.size()) - ImGui::TextUnformatted(tableContent[i * width + j].c_str()); + ImGui::TextUnformatted(tableContent[(i * width) + j].c_str()); else ImGui::TextUnformatted("??"); } diff --git a/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp b/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp index 33caedfe32691..a4b009712083b 100644 --- a/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp @@ -14,7 +14,7 @@ namespace hex::plugin::visualizers { - void drawTimestampVisualizer(pl::ptrn::Pattern &, pl::ptrn::IIterable &, bool, std::span arguments) { + void drawTimestampVisualizer(pl::ptrn::Pattern &, bool, std::span arguments) { time_t timestamp = arguments[0].toUnsigned(); auto tm = fmt::gmtime(timestamp); auto date = std::chrono::year_month_day(std::chrono::year(tm.tm_year + 1900), std::chrono::month(tm.tm_mon + 1), std::chrono::day(tm.tm_mday));