From e6ab2c3b7e9fec57088dc79d388c42a98e4fd3e8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 31 Jan 2025 19:43:39 +0100 Subject: [PATCH] impr: Various small fixes and improvements --- cmake/build_helpers.cmake | 5 +++- cmake/modules/FindmbedTLS.cmake | 7 ++++- cmake/modules/ImHexPlugin.cmake | 10 +++++-- lib/libimhex/CMakeLists.txt | 10 +++++-- .../include/hex/api/achievement_manager.hpp | 6 ++-- .../include/hex/api/localization_manager.hpp | 14 ++++++--- .../include/hex/helpers/default_paths.hpp | 1 + lib/libimhex/include/hex/helpers/opengl.hpp | 9 +++--- lib/libimhex/include/hex/helpers/utils.hpp | 2 +- .../source/api/achievement_manager.cpp | 20 ++++++------- lib/libimhex/source/api/content_registry.cpp | 16 +++++----- lib/libimhex/source/helpers/magic.cpp | 7 ++++- lib/libimhex/source/providers/provider.cpp | 2 +- .../ColorTextEditor/include/TextEditor.h | 3 +- .../ColorTextEditor/source/TextEditor.cpp | 4 ++- lib/third_party/imgui/backend/CMakeLists.txt | 12 ++++---- .../imgui/backend/include/opengl_support.h | 5 ++++ .../backend/source/imgui_impl_opengl3.cpp | 5 ++++ .../include/content/helpers/diagrams.hpp | 4 +-- .../source/content/main_menu_items.cpp | 18 +++++------ plugins/builtin/source/content/views.cpp | 2 +- .../source/content/views/view_tools.cpp | 5 ++-- plugins/disassembler/CMakeLists.txt | 4 ++- .../content/views/view_disassembler.cpp | 2 +- plugins/ui/source/ui/hex_editor.cpp | 2 +- plugins/ui/source/ui/pattern_drawer.cpp | 2 +- .../content/pl_visualizers/3d_model.cpp | 30 +++++++++---------- .../content/pl_visualizers/coordinates.cpp | 4 +-- .../source/content/pl_visualizers/sound.cpp | 2 +- .../source/content/views/view_yara.cpp | 2 +- 30 files changed, 132 insertions(+), 83 deletions(-) diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 4598e6084..d965a120c 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -73,6 +73,7 @@ macro(detectOS) set(CMAKE_INSTALL_LIBDIR ".") set(PLUGINS_INSTALL_LOCATION "plugins") add_compile_definitions(WIN32_LEAN_AND_MEAN) + add_compile_definitions(NOMINMAX) add_compile_definitions(UNICODE) elseif (APPLE) add_compile_definitions(OS_MACOS) @@ -439,6 +440,8 @@ function(verifyCompiler) message(FATAL_ERROR "ImHex requires GCC 12.0.0 or newer. Please use the latest GCC version.") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "17.0.0") message(FATAL_ERROR "ImHex requires Clang 17.0.0 or newer. Please use the latest Clang version.") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + elseif (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) message(FATAL_ERROR "ImHex can only be compiled with GCC or Clang. ${CMAKE_CXX_COMPILER_ID} is not supported.") endif() @@ -727,7 +730,7 @@ macro(addBundledLibraries) set(LIBPL_BUILD_CLI_AS_EXECUTABLE OFF CACHE BOOL "" FORCE) set(LIBPL_ENABLE_PRECOMPILED_HEADERS ${IMHEX_ENABLE_PRECOMPILED_HEADERS} CACHE BOOL "" FORCE) - if (WIN32) + if (WIN32 AND NOT MSVC) set(LIBPL_SHARED_LIBRARY ON CACHE BOOL "" FORCE) else() set(LIBPL_SHARED_LIBRARY OFF CACHE BOOL "" FORCE) diff --git a/cmake/modules/FindmbedTLS.cmake b/cmake/modules/FindmbedTLS.cmake index 4f9c73e46..fed09b86c 100644 --- a/cmake/modules/FindmbedTLS.cmake +++ b/cmake/modules/FindmbedTLS.cmake @@ -40,7 +40,12 @@ IF(MBEDTLS_FOUND) STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) - SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") + + if (MSVC) + SET(MBEDTLS_LIBRARIES ${MBEDTLS_LIBRARY_FILE}.lib ${MBEDX509_LIBRARY_FILE}.lib ${MBEDCRYPTO_LIBRARY_FILE}.lib) + else() + SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") + endif() IF(NOT MBEDTLS_FIND_QUIETLY) MESSAGE(STATUS "Found mbedTLS:") diff --git a/cmake/modules/ImHexPlugin.cmake b/cmake/modules/ImHexPlugin.cmake index b20b0e50a..eed1ad0bd 100644 --- a/cmake/modules/ImHexPlugin.cmake +++ b/cmake/modules/ImHexPlugin.cmake @@ -36,8 +36,8 @@ macro(add_imhex_plugin) # Add include directories and link libraries target_include_directories(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_INCLUDES}) - target_link_libraries(${IMHEX_PLUGIN_NAME} PUBLIC ${IMHEX_PLUGIN_LIBRARIES}) - target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE libimhex ${FMT_LIBRARIES} imgui_all_includes libwolv) + target_link_libraries(${IMHEX_PLUGIN_NAME} PUBLIC libimhex) + target_link_libraries(${IMHEX_PLUGIN_NAME} PRIVATE ${FMT_LIBRARIES} imgui_all_includes libwolv ${IMHEX_PLUGIN_LIBRARIES}) addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl) addIncludesFromLibrary(${IMHEX_PLUGIN_NAME} libpl-gen) @@ -62,7 +62,11 @@ macro(add_imhex_plugin) ) # Set rpath of plugin libraries to the plugins folder - if (APPLE) + if (WIN32) + if (IMHEX_PLUGIN_LIBRARY_PLUGIN) + set_target_properties(${IMHEX_PLUGIN_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + endif() + elseif (APPLE) set_target_properties(${IMHEX_PLUGIN_NAME} PROPERTIES BUILD_RPATH "@executable_path/../Frameworks;@executable_path/plugins") endif() diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index f419e6c1b..f505d9d93 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -134,16 +134,22 @@ endif() if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD) if (WIN32) set_target_properties(libimhex PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) - target_link_options(libimhex PRIVATE -Wl,--export-all-symbols) + if (NOT MSVC) + target_link_options(libimhex PRIVATE -Wl,--export-all-symbols) + endif() target_link_libraries(libimhex PRIVATE Netapi32.lib) elseif (APPLE) find_library(FOUNDATION NAMES Foundation) target_link_libraries(libimhex PUBLIC ${FOUNDATION}) endif () - target_link_libraries(libimhex PRIVATE microtar libwolv ${NFD_LIBRARIES} magic dl) + target_link_libraries(libimhex PRIVATE microtar libwolv ${NFD_LIBRARIES} magic) target_link_libraries(libimhex PUBLIC libpl ${IMGUI_LIBRARIES} ${JTHREAD_LIBRARIES}) + if (NOT WIN32) + target_link_libraries(libimhex PRIVATE dl) + endif() + precompileHeaders(libimhex "${CMAKE_CURRENT_SOURCE_DIR}/include") endif() diff --git a/lib/libimhex/include/hex/api/achievement_manager.hpp b/lib/libimhex/include/hex/api/achievement_manager.hpp index 22064c843..2f4f17a09 100644 --- a/lib/libimhex/include/hex/api/achievement_manager.hpp +++ b/lib/libimhex/include/hex/api/achievement_manager.hpp @@ -362,7 +362,7 @@ namespace hex { * @brief Returns all registered achievements * @return All achievements */ - static const std::unordered_map>>& getAchievements(); + static const std::unordered_map>>& getAchievements(); /** * @brief Returns all achievement start nodes @@ -370,14 +370,14 @@ namespace hex { * @param rebuild Whether to rebuild the list of start nodes * @return All achievement start nodes */ - static const std::unordered_map>& getAchievementStartNodes(bool rebuild = true); + static const std::unordered_map>& getAchievementStartNodes(bool rebuild = true); /** * @brief Returns all achievement nodes * @param rebuild Whether to rebuild the list of nodes * @return All achievement nodes */ - static const std::unordered_map>& getAchievementNodes(bool rebuild = true); + static const std::unordered_map>& getAchievementNodes(bool rebuild = true); /** * @brief Loads the progress of all achievements from the achievements save file diff --git a/lib/libimhex/include/hex/api/localization_manager.hpp b/lib/libimhex/include/hex/api/localization_manager.hpp index 00c1d1d98..c3db82386 100644 --- a/lib/libimhex/include/hex/api/localization_manager.hpp +++ b/lib/libimhex/include/hex/api/localization_manager.hpp @@ -101,10 +101,9 @@ namespace hex { public: UnlocalizedString() = default; - template - UnlocalizedString(T &&arg) : m_unlocalizedString(std::forward(arg)) { - static_assert(!std::same_as, Lang>, "Expected a unlocalized name, got a localized one!"); - } + UnlocalizedString(const std::string &string) : m_unlocalizedString(string) { } + UnlocalizedString(const char *string) : m_unlocalizedString(string) { } + UnlocalizedString(const Lang& arg) = delete; [[nodiscard]] operator std::string() const { return m_unlocalizedString; @@ -149,3 +148,10 @@ namespace hex { } } + +template<> +struct std::hash { + std::size_t operator()(const hex::UnlocalizedString &string) const noexcept { + return std::hash{}(string.get()); + } +}; \ No newline at end of file diff --git a/lib/libimhex/include/hex/helpers/default_paths.hpp b/lib/libimhex/include/hex/helpers/default_paths.hpp index cd8b67545..042884f0f 100644 --- a/lib/libimhex/include/hex/helpers/default_paths.hpp +++ b/lib/libimhex/include/hex/helpers/default_paths.hpp @@ -2,6 +2,7 @@ #include +#include #include namespace hex::paths { diff --git a/lib/libimhex/include/hex/helpers/opengl.hpp b/lib/libimhex/include/hex/helpers/opengl.hpp index 6efbefb0d..bb6cfe093 100644 --- a/lib/libimhex/include/hex/helpers/opengl.hpp +++ b/lib/libimhex/include/hex/helpers/opengl.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -219,11 +220,11 @@ namespace hex::gl { this->mat[row*Columns + col] = value; } - T &operator()( const int &row,const int &col) { + T &operator()( const unsigned&row, const unsigned&col) { return this->mat[row*Columns + col]; } - const T &operator()(const unsigned& row,const unsigned& col ) const { + const T &operator()(const unsigned& row, const unsigned& col) const { return this->mat[row*Columns + col]; } @@ -401,7 +402,7 @@ namespace hex::gl { T Sx, Cx, Sy, Cy, Sz, Cz; Vector angles = ypr; if(!radians) - angles *= M_PI/180; + angles *= std::numbers::pi / 180; Sx = -sin(angles[0]); Cx = cos(angles[0]); Sy = -sin(angles[1]); Cy = cos(angles[1]); @@ -524,7 +525,7 @@ namespace hex::gl { Vector rotationVector3 = {{rotationVector[0], rotationVector[1], rotationVector[2]}}; T theta = rotationVector3.magnitude(); if (!radians) - theta *= M_PI / 180; + theta *= std::numbers::pi / 180; Vector axis = rotationVector3; if (theta != 0) axis = axis.normalize(); diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index 2808078be..42480e3b6 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -37,7 +37,7 @@ namespace hex { template [[nodiscard]] std::vector> sampleChannels(const std::vector &data, size_t count, size_t channels) { if (channels == 0) return {}; - size_t signalLength = std::max(1.0, double(data.size()) / channels); + size_t signalLength = std::max(1.0, double(data.size()) / channels); size_t stride = std::max(1.0, double(signalLength) / count); diff --git a/lib/libimhex/source/api/achievement_manager.cpp b/lib/libimhex/source/api/achievement_manager.cpp index a346532e0..dfa9811c9 100644 --- a/lib/libimhex/source/api/achievement_manager.cpp +++ b/lib/libimhex/source/api/achievement_manager.cpp @@ -12,13 +12,13 @@ namespace hex { - static AutoReset>>> s_achievements; - const std::unordered_map>> &AchievementManager::getAchievements() { + static AutoReset>>> s_achievements; + const std::unordered_map>> &AchievementManager::getAchievements() { return *s_achievements; } - static AutoReset>> s_nodeCategoryStorage; - std::unordered_map>& getAchievementNodesMutable(bool rebuild) { + static AutoReset>> s_nodeCategoryStorage; + std::unordered_map>& getAchievementNodesMutable(bool rebuild) { if (!s_nodeCategoryStorage->empty() || !rebuild) return s_nodeCategoryStorage; @@ -36,12 +36,12 @@ namespace hex { return s_nodeCategoryStorage; } - const std::unordered_map>& AchievementManager::getAchievementNodes(bool rebuild) { + const std::unordered_map>& AchievementManager::getAchievementNodes(bool rebuild) { return getAchievementNodesMutable(rebuild); } - static AutoReset>> s_startNodes; - const std::unordered_map>& AchievementManager::getAchievementStartNodes(bool rebuild) { + static AutoReset>> s_startNodes; + const std::unordered_map>& AchievementManager::getAchievementStartNodes(bool rebuild) { if (!s_startNodes->empty() || !rebuild) return s_startNodes; @@ -187,10 +187,10 @@ namespace hex { const auto &category = newAchievement->getUnlocalizedCategory(); const auto &name = newAchievement->getUnlocalizedName(); - auto [categoryIter, categoryInserted] = s_achievements->insert({ category, std::unordered_map>{} }); + auto [categoryIter, categoryInserted] = s_achievements->insert({ category, std::unordered_map>{} }); auto &[categoryKey, achievements] = *categoryIter; - auto [achievementIter, achievementInserted] = achievements.insert({ name, std::move(newAchievement) }); + auto [achievementIter, achievementInserted] = achievements.emplace(name, std::move(newAchievement)); auto &[achievementKey, achievement] = *achievementIter; achievementAdded(); @@ -239,7 +239,7 @@ namespace hex { achievement->setProgress(progress); } catch (const std::exception &e) { - log::warn("Failed to load achievement progress for '{}::{}': {}", categoryName, achievementName, e.what()); + log::warn("Failed to load achievement progress for '{}::{}': {}", categoryName.get(), achievementName.get(), e.what()); } } } diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index e772b4aa9..ffc43a346 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -33,7 +33,7 @@ namespace hex { namespace impl { struct OnChange { - u32 id; + u64 id; OnChangeCallback callback; }; @@ -714,15 +714,15 @@ namespace hex { namespace impl { - static AutoReset>> s_views; - const std::map>& getEntries() { + static AutoReset>> s_views; + const std::map>& getEntries() { return *s_views; } void add(std::unique_ptr &&view) { log::debug("Registered new view: {}", view->getUnlocalizedName().get()); - s_views->insert({ view->getUnlocalizedName(), std::move(view) }); + s_views->emplace(view->getUnlocalizedName(), std::move(view)); } } @@ -1126,7 +1126,9 @@ namespace hex { namespace ContentRegistry::HexEditor { - const int DataVisualizer::TextInputFlags = ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_AlwaysOverwrite; + int DataVisualizer::DefaultTextInputFlags() { + return ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoHorizontalScroll | ImGuiInputTextFlags_AlwaysOverwrite; + } bool DataVisualizer::drawDefaultScalarEditingTextBox(u64 address, const char *format, ImGuiDataType dataType, u8 *data, ImGuiInputTextFlags flags) const { struct UserData { @@ -1144,7 +1146,7 @@ namespace hex { }; ImGui::PushID(reinterpret_cast(address)); - ImGuiExt::InputScalarCallback("##editing_input", dataType, data, format, flags | TextInputFlags | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int { + ImGuiExt::InputScalarCallback("##editing_input", dataType, data, format, flags | DefaultTextInputFlags() | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int { auto &userData = *static_cast(data->UserData); if (data->CursorPos >= userData.maxChars) @@ -1175,7 +1177,7 @@ namespace hex { }; ImGui::PushID(reinterpret_cast(address)); - ImGui::InputText("##editing_input", data.data(), data.size() + 1, flags | TextInputFlags | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int { + ImGui::InputText("##editing_input", data.data(), data.size() + 1, flags | DefaultTextInputFlags() | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int { auto &userData = *static_cast(data->UserData); userData.data->resize(data->BufSize); diff --git a/lib/libimhex/source/helpers/magic.cpp b/lib/libimhex/source/helpers/magic.cpp index aa6fe70ab..3979e3450 100644 --- a/lib/libimhex/source/helpers/magic.cpp +++ b/lib/libimhex/source/helpers/magic.cpp @@ -15,7 +15,12 @@ #include #include -#include + +#if defined(_MSC_VER) + #include +#else + #include +#endif #if defined(OS_WINDOWS) #define MAGIC_PATH_SEPARATOR ";" diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index 10a6370b5..80a009287 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -332,7 +332,7 @@ namespace hex::prv { else if (category == "description") return magic::getDescription(this); else if (category == "provider_type") - return this->getTypeName(); + return this->getTypeName().get(); else return 0; } diff --git a/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h b/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h index e4521ce70..781bd97be 100644 --- a/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h +++ b/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h @@ -289,7 +289,7 @@ public: void SetLanguageDefinition(const LanguageDefinition& aLanguageDef); const LanguageDefinition& GetLanguageDefinition() const { return mLanguageDefinition; } - static const Palette& GetPalette() { return sPaletteBase; } + static const Palette& GetPalette(); static void SetPalette(const Palette& aValue); void SetErrorMarkers(const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; } @@ -613,7 +613,6 @@ private: bool mIgnoreImGuiChild = false; bool mShowWhitespaces = true; - static Palette sPaletteBase; Palette mPalette = {}; LanguageDefinition mLanguageDefinition = {}; RegexList mRegexList; diff --git a/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp b/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp index d5e60ff54..a159cce7c 100644 --- a/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp +++ b/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp @@ -25,7 +25,7 @@ bool equals(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Bi const int TextEditor::sCursorBlinkInterval = 1200; const int TextEditor::sCursorBlinkOnTime = 800; -TextEditor::Palette TextEditor::sPaletteBase = TextEditor::GetDarkPalette(); +TextEditor::Palette sPaletteBase = TextEditor::GetDarkPalette(); TextEditor::FindReplaceHandler::FindReplaceHandler() : mWholeWord(false),mFindRegEx(false),mMatchCase(false) {} @@ -79,6 +79,8 @@ void TextEditor::SetLanguageDefinition(const LanguageDefinition &aLanguageDef) { Colorize(); } +const TextEditor::Palette& TextEditor::GetPalette() { return sPaletteBase; } + void TextEditor::SetPalette(const Palette &aValue) { sPaletteBase = aValue; } diff --git a/lib/third_party/imgui/backend/CMakeLists.txt b/lib/third_party/imgui/backend/CMakeLists.txt index 0d6b78c47..f9085aea3 100644 --- a/lib/third_party/imgui/backend/CMakeLists.txt +++ b/lib/third_party/imgui/backend/CMakeLists.txt @@ -25,16 +25,18 @@ if (NOT IMHEX_EXTERNAL_PLUGIN_BUILD) set(GLFW_INCLUDE_DIRS ${glfw3_INCLUDE_DIRS}) set(GLFW_LIBRARIES ${glfw3_LIBRARIES}) - if (NOT glfw3_FOUND OR "${GLFW_LIBRARIES}" STREQUAL "") + if (NOT glfw3_FOUND AND "${GLFW_LIBRARIES}" STREQUAL "") find_package(PkgConfig REQUIRED) pkg_search_module(GLFW REQUIRED glfw3) + + if ("${GLFW_LIBRARIES}" MATCHES ".+dll") + set(GLFW_LIBRARIES "glfw3") + endif () + else() + set(GLFW_LIBRARIES GLFW::GLFW) endif () endif() - if ("${GLFW_LIBRARIES}" MATCHES ".+dll") - set(GLFW_LIBRARIES "glfw3") - endif () - target_include_directories(imgui_backend PUBLIC ${FREETYPE_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS}) target_link_directories(imgui_backend PUBLIC ${FREETYPE_LIBRARY_DIRS} ${OpenGL_LIBRARY_DIRS}) target_link_libraries(imgui_backend PUBLIC ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES}) diff --git a/lib/third_party/imgui/backend/include/opengl_support.h b/lib/third_party/imgui/backend/include/opengl_support.h index 7f5458f36..c7697cf24 100644 --- a/lib/third_party/imgui/backend/include/opengl_support.h +++ b/lib/third_party/imgui/backend/include/opengl_support.h @@ -1,5 +1,10 @@ #pragma once +#if !defined(WINGDIAPI) +#define WINGDIAPI extern "C" +#define APIENTRY +#endif + #if defined(OS_WEB) #define GLFW_INCLUDE_ES3 #include diff --git a/lib/third_party/imgui/backend/source/imgui_impl_opengl3.cpp b/lib/third_party/imgui/backend/source/imgui_impl_opengl3.cpp index 46345d220..6e27f0e85 100644 --- a/lib/third_party/imgui/backend/source/imgui_impl_opengl3.cpp +++ b/lib/third_party/imgui/backend/source/imgui_impl_opengl3.cpp @@ -113,6 +113,11 @@ #define _CRT_SECURE_NO_WARNINGS #endif +#if !defined(WINGDIAPI) +#define WINGDIAPI extern "C" +#define APIENTRY +#endif + #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_opengl3.h" diff --git a/plugins/builtin/include/content/helpers/diagrams.hpp b/plugins/builtin/include/content/helpers/diagrams.hpp index 3374869e9..d844d0d99 100644 --- a/plugins/builtin/include/content/helpers/diagrams.hpp +++ b/plugins/builtin/include/content/helpers/diagrams.hpp @@ -56,7 +56,7 @@ namespace hex { std::map> orderedData; for (u32 i = 0; i < sequenceCount; i++) { - ssize_t offset = random() % size; + i64 offset = random() % size; std::vector sequence; sequence.resize(std::min(sequenceCount, size - offset)); @@ -93,7 +93,7 @@ namespace hex { std::map> orderedData; for (u32 i = 0; i < sequenceCount; i++) { - ssize_t offset = random() % inputBuffer.size(); + i64 offset = random() % inputBuffer.size(); std::vector sequence; sequence.reserve(sampleSize); diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp index 3669e3731..cea1c4fc6 100644 --- a/plugins/builtin/source/content/main_menu_items.cpp +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -78,7 +78,7 @@ namespace hex::plugin::builtin { void importIPSPatch() { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [path](auto &task) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [path](auto &task) { auto patchData = wolv::io::File(path, wolv::io::File::Mode::Read).readVector(); auto patch = Patches::fromIPSPatch(patchData); if (!patch.has_value()) { @@ -102,7 +102,7 @@ namespace hex::plugin::builtin { void importIPS32Patch() { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [path](auto &task) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [path](auto &task) { auto patchData = wolv::io::File(path, wolv::io::File::Mode::Read).readVector(); auto patch = Patches::fromIPS32Patch(patchData); if (!patch.has_value()) { @@ -126,7 +126,7 @@ namespace hex::plugin::builtin { void importModifiedFile() { fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [path](auto &task) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [path](auto &task) { auto provider = ImHexApi::Provider::get(); auto patchData = wolv::io::File(path, wolv::io::File::Mode::Read).readVector(); @@ -165,7 +165,7 @@ namespace hex::plugin::builtin { void exportBase64() { fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [path](auto &) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [path](auto &) { wolv::io::File outputFile(path, wolv::io::File::Mode::Create); if (!outputFile.isValid()) { TaskManager::doLater([] { @@ -188,7 +188,7 @@ namespace hex::plugin::builtin { void exportSelectionToFile() { fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [path](auto &task) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [path](auto &task) { wolv::io::File outputFile(path, wolv::io::File::Mode::Create); if (!outputFile.isValid()) { TaskManager::doLater([] { @@ -216,7 +216,7 @@ namespace hex::plugin::builtin { for (const auto &formatter : ContentRegistry::DataFormatter::impl::getExportMenuEntries()) { if (menu::menuItem(Lang(formatter.unlocalizedName), Shortcut::None, false, ImHexApi::Provider::isValid() && ImHexApi::Provider::get()->getActualSize() > 0)) { fs::openFileBrowser(fs::DialogMode::Save, {}, [&formatter](const auto &path) { - TaskManager::createTask("hex.builtin.task.exporting_data"_lang, TaskManager::NoProgress, [&formatter, path](auto&){ + TaskManager::createTask("hex.builtin.task.exporting_data", TaskManager::NoProgress, [&formatter, path](auto&){ auto provider = ImHexApi::Provider::get(); auto selection = ImHexApi::HexEditor::getSelection() .value_or( @@ -243,7 +243,7 @@ namespace hex::plugin::builtin { } void exportReport() { - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [](auto &) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [](auto &) { std::string data; for (const auto &provider : ImHexApi::Provider::getProviders()) { @@ -287,7 +287,7 @@ namespace hex::plugin::builtin { patches->get().at(0x00454F45) = value; } - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [patches](auto &) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [patches](auto &) { auto data = patches->toIPSPatch(); TaskManager::doLater([data] { @@ -326,7 +326,7 @@ namespace hex::plugin::builtin { patches->get().at(0x45454F45) = value; } - TaskManager::createTask("hex.ui.common.processing"_lang, TaskManager::NoProgress, [patches](auto &) { + TaskManager::createTask("hex.ui.common.processing", TaskManager::NoProgress, [patches](auto &) { auto data = patches->toIPS32Patch(); TaskManager::doLater([data] { diff --git a/plugins/builtin/source/content/views.cpp b/plugins/builtin/source/content/views.cpp index 4fe87583d..39d8317ea 100644 --- a/plugins/builtin/source/content/views.cpp +++ b/plugins/builtin/source/content/views.cpp @@ -63,7 +63,7 @@ namespace hex::plugin::builtin { if (!view->shouldStoreWindowState()) continue; - buffer->appendf("%s=%d\n", name.c_str(), view->getWindowOpenState()); + buffer->appendf("%s=%d\n", name.get().c_str(), view->getWindowOpenState()); } }); } diff --git a/plugins/builtin/source/content/views/view_tools.cpp b/plugins/builtin/source/content/views/view_tools.cpp index e32df058f..6f79bd176 100644 --- a/plugins/builtin/source/content/views/view_tools.cpp +++ b/plugins/builtin/source/content/views/view_tools.cpp @@ -90,8 +90,9 @@ namespace hex::plugin::builtin { m_dragStartIterator = tools.end(); // Attach the newly created window to the cursor, so it gets dragged around - GImGui->MovingWindow = ImGui::GetCurrentWindowRead(); - GImGui->ActiveId = GImGui->MovingWindow->MoveId; + auto& g = *ImGui::GetCurrentContext(); + g.MovingWindow = ImGui::GetCurrentWindowRead(); + g.ActiveId = g.MovingWindow->MoveId; } const auto window = ImGui::GetCurrentWindowRead(); diff --git a/plugins/disassembler/CMakeLists.txt b/plugins/disassembler/CMakeLists.txt index 13f7c1701..4420e7ba8 100644 --- a/plugins/disassembler/CMakeLists.txt +++ b/plugins/disassembler/CMakeLists.txt @@ -8,7 +8,9 @@ if (NOT USE_SYSTEM_CAPSTONE) set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "Disable tests") set(CAPSTONE_BUILD_MACOS_THIN ON CACHE BOOL "Enable thin builds of capstone for macOS" FORCE) add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/capstone ${CMAKE_CURRENT_BINARY_DIR}/capstone EXCLUDE_FROM_ALL) - target_compile_options(capstone PRIVATE -Wno-unused-function) + if (NOT MSVC) + target_compile_options(capstone PRIVATE -Wno-unused-function) + endif() set(CAPSTONE_LIBRARY "capstone") set(CAPSTONE_INCLUDE_DIR ${THIRD_PARTY_LIBS_FOLDER}/capstone/include) else() diff --git a/plugins/disassembler/source/content/views/view_disassembler.cpp b/plugins/disassembler/source/content/views/view_disassembler.cpp index 83d6832dc..dcb74f413 100644 --- a/plugins/disassembler/source/content/views/view_disassembler.cpp +++ b/plugins/disassembler/source/content/views/view_disassembler.cpp @@ -47,7 +47,7 @@ namespace hex::plugin::disasm { if (m_regionToDisassemble.get(provider).getStartAddress() < m_imageBaseAddress) return; - m_disassemblerTask = TaskManager::createTask("hex.disassembler.view.disassembler.disassembling"_lang, m_regionToDisassemble.get(provider).getSize(), [this, provider](auto &task) { + m_disassemblerTask = TaskManager::createTask("hex.disassembler.view.disassembler.disassembling", m_regionToDisassemble.get(provider).getSize(), [this, provider](auto &task) { const auto &currArchitecture = m_currArchitecture.get(provider); const auto region = m_regionToDisassemble.get(provider); auto &disassembly = m_disassembly.get(provider); diff --git a/plugins/ui/source/ui/hex_editor.cpp b/plugins/ui/source/ui/hex_editor.cpp index 3b31393a2..a4a5e0002 100644 --- a/plugins/ui/source/ui/hex_editor.cpp +++ b/plugins/ui/source/ui/hex_editor.cpp @@ -62,7 +62,7 @@ namespace hex::ui { ImGui::PushID(reinterpret_cast(address)); ON_SCOPE_EXIT { ImGui::PopID(); }; std::array buffer = { std::isprint(data[0]) != 0 ? char(data[0]) : '.', 0x00 }; - ImGui::InputText("##editing_input", buffer.data(), buffer.size(), TextInputFlags | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int { + ImGui::InputText("##editing_input", buffer.data(), buffer.size(), DefaultTextInputFlags() | ImGuiInputTextFlags_CallbackEdit, [](ImGuiInputTextCallbackData *data) -> int { auto &userData = *static_cast(data->UserData); if (data->BufTextLen >= userData.maxChars) { diff --git a/plugins/ui/source/ui/pattern_drawer.cpp b/plugins/ui/source/ui/pattern_drawer.cpp index 6280114df..1ae12ea2d 100644 --- a/plugins/ui/source/ui/pattern_drawer.cpp +++ b/plugins/ui/source/ui/pattern_drawer.cpp @@ -1397,7 +1397,7 @@ namespace hex::ui { m_filtersUpdated = true; if (!m_favoritesUpdateTask.isRunning()) { - m_favoritesUpdateTask = TaskManager::createTask("hex.ui.pattern_drawer.updating"_lang, TaskManager::NoProgress, [this, patterns, runtime](auto &task) { + m_favoritesUpdateTask = TaskManager::createTask("hex.ui.pattern_drawer.updating", TaskManager::NoProgress, [this, patterns, runtime](auto &task) { size_t updatedFavorites = 0; { diff --git a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp index 3d8ec7e1e..927330a03 100644 --- a/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/3d_model.cpp @@ -342,7 +342,7 @@ namespace hex::plugin::visualizers { rotation[2] = std::fmod(rotation[2], 2 * std::numbers::pi_v); } - bool validateVector(const std::vector &vector, u32 vertexCount, u32 divisor, const std::string &name,std::string &errorMessage) { + bool validateVector(const std::vector &vector, u32 vertexCount, u32 divisor, const std::string &name, std::string &errorMessage) { if (!vector.empty()) { if (vector.size() % divisor != 0) { errorMessage = hex::format("hex.visualizers.pl_visualizer.3d.error_message_count"_lang, name , std::to_string(divisor)); @@ -377,24 +377,24 @@ namespace hex::plugin::visualizers { if ((indexType == IndexType::Undefined || vectors.indices.empty()) && vertexCount % 3 != 0) { - throw std::runtime_error(std::string("hex.visualizers.pl_visualizer.3d.error_message_vertex_count"_lang)); + throw std::runtime_error("hex.visualizers.pl_visualizer.3d.error_message_vertex_count"_lang.get()); } else buffers.vertices = gl::Buffer(gl::BufferType::Vertex, vectors.vertices); - if (validateVector(vectors.colors, vertexCount, 4, std::string("hex.visualizers.pl_visualizer.3d.error_message_colors"_lang), errorMessage)) + if (validateVector(vectors.colors, vertexCount, 4, "hex.visualizers.pl_visualizer.3d.error_message_colors"_lang.get(), errorMessage)) buffers.colors = gl::Buffer(gl::BufferType::Vertex, vectors.colors); else { throw std::runtime_error(errorMessage); } - if (validateVector(vectors.normals, vertexCount, 3, std::string("hex.visualizers.pl_visualizer.3d.error_message_normals"_lang), errorMessage)) + if (validateVector(vectors.normals, vertexCount, 3, "hex.visualizers.pl_visualizer.3d.error_message_normals"_lang.get(), errorMessage)) buffers.normals = gl::Buffer(gl::BufferType::Vertex, vectors.normals); else { throw std::runtime_error(errorMessage); } - if (validateVector(vectors.uv, vertexCount, 2, std::string("hex.visualizers.pl_visualizer.3d.error_message_uv_coords"_lang), errorMessage)) + if (validateVector(vectors.uv, vertexCount, 2, "hex.visualizers.pl_visualizer.3d.error_message_uv_coords"_lang.get(), errorMessage)) buffers.uv = gl::Buffer(gl::BufferType::Vertex, vectors.uv); else { throw std::runtime_error(errorMessage); @@ -430,11 +430,11 @@ namespace hex::plugin::visualizers { lineBuffers.indices = gl::Buffer(gl::BufferType::Index, lineVectors.indices); if ((indexType == IndexType::Undefined || lineVectors.indices.empty()) && vertexCount % 3 != 0) { - throw std::runtime_error(std::string("hex.visualizers.pl_visualizer.3d.error_message_vertex_count"_lang)); + throw std::runtime_error("hex.visualizers.pl_visualizer.3d.error_message_vertex_count"_lang.get()); } else lineBuffers.vertices = gl::Buffer(gl::BufferType::Vertex, lineVectors.vertices); - if (validateVector(lineVectors.colors, vertexCount, 4, std::string("hex.visualizers.pl_visualizer.3d.error_message_colors"_lang), errorMessage)) + if (validateVector(lineVectors.colors, vertexCount, 4, "hex.visualizers.pl_visualizer.3d.error_message_colors"_lang.get(), errorMessage)) lineBuffers.colors = gl::Buffer(gl::BufferType::Vertex, lineVectors.colors); else { throw std::runtime_error(errorMessage); @@ -644,7 +644,7 @@ namespace hex::plugin::visualizers { vectors.vertices = patternToArray(verticesPattern.get()); std::string errorMessage; s_vertexCount = vectors.vertices.size() / 3; - if (!validateVector(vectors.vertices, s_vertexCount, 3, std::string("hex.visualizers.pl_visualizer.3d.error_message_positions"_lang), errorMessage)) + if (!validateVector(vectors.vertices, s_vertexCount, 3, "hex.visualizers.pl_visualizer.3d.error_message_positions"_lang, errorMessage)) throw std::runtime_error(errorMessage); if (s_indexType != IndexType::Undefined) { @@ -652,16 +652,16 @@ namespace hex::plugin::visualizers { s_badIndices.clear(); auto indexCount = vectors.indices.size(); if (indexCount < 3 || indexCount % 3 != 0) { - throw std::runtime_error(std::string("hex.visualizers.pl_visualizer.3d.error_message_index_count"_lang)); + throw std::runtime_error("hex.visualizers.pl_visualizer.3d.error_message_index_count"_lang.get()); } auto booleans = std::views::transform(vectors.indices,isIndexInRange); if (!std::accumulate(std::begin(booleans), std::end(booleans), true, std::logical_and<>())) { - errorMessage = std::string("hex.visualizers.pl_visualizer.3d.error_message_invalid_indices"_lang); + errorMessage = "hex.visualizers.pl_visualizer.3d.error_message_invalid_indices"_lang.get(); for (auto badIndex : s_badIndices) errorMessage += std::to_string(badIndex) + ", "; errorMessage.pop_back(); errorMessage.pop_back(); - errorMessage += hex::format(std::string("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang),s_vertexCount); + errorMessage += hex::format("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang.get(), s_vertexCount); throw std::runtime_error(errorMessage); } } @@ -682,23 +682,23 @@ namespace hex::plugin::visualizers { lineVectors.vertices = patternToArray(verticesPattern.get()); s_vertexCount = lineVectors.vertices.size() / 3; - if (!validateVector(lineVectors.vertices, s_vertexCount, 3, std::string("hex.visualizers.pl_visualizer.3d.error_message_positions"_lang), errorMessage)) + if (!validateVector(lineVectors.vertices, s_vertexCount, 3, "hex.visualizers.pl_visualizer.3d.error_message_positions"_lang.get(), errorMessage)) throw std::runtime_error(errorMessage); if (s_indexType != IndexType::Undefined) { lineVectors.indices = patternToArray(indicesPattern.get()); auto indexCount = lineVectors.indices.size(); if (indexCount < 3 || indexCount % 3 != 0) { - throw std::runtime_error(std::string("hex.visualizers.pl_visualizer.3d.error_message_index_count"_lang)); + throw std::runtime_error("hex.visualizers.pl_visualizer.3d.error_message_index_count"_lang.get()); } s_badIndices.clear(); if (!std::ranges::all_of(lineVectors.indices,isIndexInRange)) { - errorMessage = std::string("hex.visualizers.pl_visualizer.3d.error_message_invalid_indices"_lang); + errorMessage = "hex.visualizers.pl_visualizer.3d.error_message_invalid_indices"_lang.get(); for (auto badIndex : s_badIndices) errorMessage += std::to_string(badIndex) + ", "; errorMessage.pop_back(); errorMessage.pop_back(); - errorMessage += hex::format(std::string("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang),s_vertexCount); + errorMessage += hex::format("hex.visualizers.pl_visualizer.3d.error_message_for_vertex_count"_lang.get(), s_vertexCount); throw std::runtime_error(errorMessage); } } diff --git a/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp b/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp index 11f974b01..d1bc602b2 100644 --- a/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/coordinates.cpp @@ -60,7 +60,7 @@ namespace hex::plugin::visualizers { ImGuiExt::TextSpinner("hex.visualizers.pl_visualizer.coordinates.querying"_lang); } else if (address.empty()) { if (ImGuiExt::DimmedButton("hex.visualizers.pl_visualizer.coordinates.query"_lang)) { - addressTask = TaskManager::createBackgroundTask("hex.visualizers.pl_visualizer.coordinates.querying"_lang, [lat = latitude, lon = longitude](auto &) { + addressTask = TaskManager::createBackgroundTask("hex.visualizers.pl_visualizer.coordinates.querying", [lat = latitude, lon = longitude](auto &) { constexpr static auto ApiURL = "https://geocode.maps.co/reverse?lat={}&lon={}&format=jsonv2"; HttpRequest request("GET", hex::format(ApiURL, lat, lon)); @@ -90,7 +90,7 @@ namespace hex::plugin::visualizers { jsonAddr["country"].get()); } } catch (std::exception &) { - address = std::string("hex.visualizers.pl_visualizer.coordinates.querying_no_address"_lang); + address = "hex.visualizers.pl_visualizer.coordinates.querying_no_address"_lang.get(); } }); } diff --git a/plugins/visualizers/source/content/pl_visualizers/sound.cpp b/plugins/visualizers/source/content/pl_visualizers/sound.cpp index 557460235..e72d2e211 100644 --- a/plugins/visualizers/source/content/pl_visualizers/sound.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/sound.cpp @@ -35,7 +35,7 @@ namespace hex::plugin::visualizers { if (shouldReset) { waveData.clear(); - resetTask = TaskManager::createTask("hex.visualizers.pl_visualizer.task.visualizing"_lang, TaskManager::NoProgress, [=](Task &) { + resetTask = TaskManager::createTask("hex.visualizers.pl_visualizer.task.visualizing", TaskManager::NoProgress, [=](Task &) { ma_device_stop(&audioDevice); waveData = patternToArray(wavePattern.get()); if (waveData.empty()) diff --git a/plugins/yara_rules/source/content/views/view_yara.cpp b/plugins/yara_rules/source/content/views/view_yara.cpp index 6325f7eb3..94c9446f1 100644 --- a/plugins/yara_rules/source/content/views/view_yara.cpp +++ b/plugins/yara_rules/source/content/views/view_yara.cpp @@ -250,7 +250,7 @@ namespace hex::plugin::yara { if (provider == nullptr) return; - m_matcherTask = TaskManager::createTask("hex.yara_rules.view.yara.matching"_lang, 0, [this, provider](auto &task) { + m_matcherTask = TaskManager::createTask("hex.yara_rules.view.yara.matching", 0, [this, provider](auto &task) { std::vector results; for (const auto &[fileName, filePath] : *m_rulePaths) { YaraRule rule(filePath);