Add support for custom providers via plugins

This commit is contained in:
WerWolv
2020-12-27 15:39:06 +01:00
parent 8ba96904a6
commit f74eff8934
33 changed files with 286 additions and 193 deletions

View File

@@ -3,10 +3,7 @@ project(example)
set(CMAKE_CXX_STANDARD 20)
if (TARGET ${CMAKE_PROJECT_NAME})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../external/ImGui ${CMAKE_CURRENT_BINARY_DIR}/external/ImGui)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
set(CMAKE_SHARED_LIBRARY_PREFIX "plugin")
@@ -14,5 +11,5 @@ add_library(example SHARED
source/plugin_example.cpp
)
target_include_directories(example PUBLIC include)
target_link_libraries(example PRIVATE imgui libimhex)
target_include_directories(example PRIVATE include)
target_link_libraries(example PRIVATE libimhex)

View File

@@ -1,7 +1,6 @@
#include <hex.hpp>
#include <plugin.hpp>
#include <views/view.hpp>
#include <imgui.h>
class ViewExample : public hex::View {
public:

View File

@@ -17,4 +17,4 @@ add_library(libimhex STATIC
)
target_include_directories(libimhex PUBLIC include)
target_link_libraries(libimhex PRIVATE imgui)
target_link_libraries(libimhex PUBLIC imgui)

View File

@@ -2,6 +2,7 @@
#include <cstdint>
#include <cstddef>
#include <type_traits>
using u8 = std::uint8_t;
using u16 = std::uint16_t;
@@ -18,16 +19,56 @@ using s128 = __int128_t;
extern int mainArgc;
extern char **mainArgv;
#define IMHEX_PLUGIN namespace hex::plugin::internal { \
void setImGuiContext(ImGuiContext *ctx) { \
gladLoadGL(); \
ImGui::SetCurrentContext(ctx); \
} \
} \
namespace hex::plugin
#ifdef OS_WINDOWS
#define MAGIC_PATH_SEPARATOR ";"
#else
#define MAGIC_PATH_SEPARATOR ":"
#endif
template<>
struct std::is_integral<u128> : public std::true_type { };
template<>
struct std::is_integral<s128> : public std::true_type { };
template<>
struct std::is_signed<s128> : public std::true_type { };
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 12000
#if __has_include(<concepts>)
// Make sure we break when derived_from is implemented in libc++. Then we can fix a compatibility version above
#include <concepts>
#endif
// libcxx 12 still doesn't have many default concepts implemented, as a result we need to define it ourself using clang built-ins.
// [concept.derived] (patch from https://reviews.llvm.org/D74292)
namespace hex {
template<class _Dp, class _Bp>
concept derived_from =
__is_base_of(_Bp, _Dp) && __is_convertible_to(const volatile _Dp*, const volatile _Bp*);
}
// [concepts.arithmetic] (patch from https://reviews.llvm.org/D88131)
namespace hex {
template<class _Tp>
concept integral = __is_integral(_Tp);
template<class _Tp>
concept signed_integral = integral<_Tp> && __is_signed(_Tp);
template<class _Tp>
concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
template<class _Tp>
concept floating_point = __is_floating_point(_Tp);
}
#else
// Assume supported
#include <concepts>
namespace hex {
using std::derived_from;
using std::integral;
using std::signed_integral;
using std::unsigned_integral;
using std::floating_point;
}
#endif

View File

@@ -0,0 +1,18 @@
#pragma once
#include <glad/glad.h>
#include <imgui.h>
#include <hex.hpp>
#include <views/view.hpp>
#include <providers/provider.hpp>
#define IMHEX_PLUGIN namespace hex::plugin::internal { \
void initializePlugin(ImGuiContext *ctx, hex::prv::Provider **provider) { \
if (glGetString == NULL) \
gladLoadGL(); \
ImGui::SetCurrentContext(ctx); \
hex::prv::Provider::setProviderStorage(*provider); \
} \
} \
namespace hex::plugin

View File

@@ -40,10 +40,20 @@ namespace hex::prv {
virtual std::vector<std::pair<std::string, std::string>> getDataInformation() = 0;
static void setProviderStorage(Provider* &provider) {
Provider::s_currProvider = &provider;
}
static Provider*& getCurrentProvider() {
return *Provider::s_currProvider;
}
protected:
u32 m_currPage = 0;
std::vector<std::map<u64, u8>> m_patches;
static inline Provider **s_currProvider = nullptr;
};
}