diff --git a/build.py b/build.py index 21ed48e0..7ea17485 100644 --- a/build.py +++ b/build.py @@ -108,6 +108,7 @@ export( "brother120tool$(EXT)": "tools+brother120tool", "brother240tool$(EXT)": "tools+brother240tool", "upgrade-flux-file$(EXT)": "tools+upgrade-flux-file", + "plugin.hexplug": "src/gui2/+plugin", } | ( { diff --git a/src/gui2/build.py b/src/gui2/build.py new file mode 100644 index 00000000..2531b036 --- /dev/null +++ b/src/gui2/build.py @@ -0,0 +1,123 @@ +from build.c import cxxprogram, cxxlibrary, simplerule, clibrary +from build.pkg import package +from build.utils import filenamesmatchingof +from glob import glob +from functools import reduce +import operator +from os.path import * + +cflags = [ + "--std=c++23", + '-DIMHEX_PROJECT_NAME=\\"fluxengine\\"', + "-DLIBROMFS_PROJECT_NAME=fluxengine", + "-fpic", +] + + +def headers_from(path): + hdrs = {k: f"{path}/{k}" for k in glob("**/*.h*", root_dir=path, recursive=True)} + assert hdrs, f"path {path} contained no headers" + return hdrs + + +def sources_from(path): + srcs = [join(path, f) for f in glob("**/*.c*", root_dir=path, recursive=True)] + assert srcs, f"path {path} contained no sources" + return srcs + + +cxxlibrary( + name="libimgui", + srcs=[], + hdrs=reduce( + operator.ior, + [ + headers_from(f"dep/imhex/lib/third_party/imgui/{d}/include") + for d in [ + "imgui", + "backend", + "implot", + "implot3d", + "imnodes", + "cimgui", + ] + ], + ) + | { + "imgui_freetype.h": "dep/imhex/lib/third_party/imgui/imgui/include/misc/freetype/imgui_freetype.h", + }, + cflags=cflags, +) + +cxxlibrary( + name="libjson", + srcs=[], + hdrs=headers_from("dep/imhex/lib/third_party/nlohmann_json/include"), + cflags=cflags, +) + +cxxlibrary( + name="libromfs", + srcs=sources_from("dep/libromfs/lib/source"), + hdrs=headers_from("dep/libromfs/lib/include"), + cflags=cflags, +) + +cxxlibrary( + name="libwolv", + srcs=[], + hdrs=reduce( + operator.ior, + [ + headers_from(f"dep/libwolv/libs/{d}/include") + for d in ["types", "io", "utils", "containers", "hash", "math_eval"] + ], + ), + cflags=cflags, +) + +cxxlibrary( + name="libimhex", + srcs=[], + hdrs=headers_from("dep/imhex/lib/libimhex/include"), + deps=[".+libwolv", ".+libimgui", ".+libjson"], + cflags=cflags, +) + +cxxprogram( + name="mkromfs", + srcs=sources_from("dep/libromfs/generator/source"), + cflags=[ + '-DLIBROMFS_PROJECT_NAME=\\"fluxengine\\"', + '-DRESOURCE_LOCATION=\\"rsrc\\"', + ], +) + +simplerule( + name="romfs", + ins=glob("src/gui2/rsrc/*", recursive=True), + outs=["=romfs.cc"], + deps=[".+mkromfs"], + commands=[ + "ln -s $$(dirname $$(realpath $[ins[0]])) rsrc", + "$[deps[0]]", + "mv libromfs_resources.cpp $[outs[0]]", + ], + label="ROMFS", +) + +cxxlibrary( + name="plugin_lib", + srcs=["./plugin.cc", ".+romfs"], + deps=[".+libimhex", ".+libromfs"], + cflags=cflags, +) + +simplerule( + name="plugin", + ins=[".+plugin_lib", ".+libromfs"], + outs=["=plugin.hexplug"], + commands=[ + "$(CC) -shared -o $[outs[0]] -Wl,--whole-archive $[[f for f in filenamesof(ins) if f.endswith('.a')]] -Wl,--no-whole-archive" + ], +) diff --git a/src/gui2/plugin.cc b/src/gui2/plugin.cc new file mode 100644 index 00000000..77af9380 --- /dev/null +++ b/src/gui2/plugin.cc @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include +#include + +class FluxEngineProvider : public hex::prv::Provider +{ + +public: + FluxEngineProvider() + { + hex::EventProviderOpened::subscribe( + [this](auto* newProvider) + { + if (newProvider == this) + return; + + hex::ImHexApi::Provider::remove(this, true); + }); + } + + ~FluxEngineProvider() override + { + hex::EventProviderOpened::unsubscribe(this); + } + + [[nodiscard]] bool isAvailable() const override + { + return true; + } + [[nodiscard]] bool isReadable() const override + { + return true; + } + [[nodiscard]] bool isWritable() const override + { + return false; + } + [[nodiscard]] bool isResizable() const override + { + return false; + } + [[nodiscard]] bool isSavable() const override + { + return false; + } + + [[nodiscard]] bool open() override + { + return true; + } + void close() override {} + + void readRaw(u64 offset, void* buffer, size_t size) override + { + std::ignore = offset; + std::ignore = buffer; + std::ignore = size; + } + void writeRaw(u64 offset, const void* buffer, size_t size) override + { + std::ignore = offset; + std::ignore = buffer; + std::ignore = size; + } + [[nodiscard]] u64 getActualSize() const override + { + return 0x00; + } + + [[nodiscard]] std::string getName() const override + { + return "ImHex"; + } + + [[nodiscard]] const char* getIcon() const override + { + return ""; + } + + void loadSettings(const nlohmann::json& settings) override + { + std::ignore = settings; + } + + [[nodiscard]] nlohmann::json storeSettings( + nlohmann::json settings) const override + { + return settings; + } + + [[nodiscard]] hex::UnlocalizedString getTypeName() const override + { + return "fluxengine.provider.fluxengine"; + } +}; + +#define IMHEX_PLUGIN_NAME fluxengine +#define IMHEX_VERSION "" +#define IMHEX_PLUGIN_FEATURES_CONTENT \ + { \ + } +IMHEX_PLUGIN_SETUP("FluxEngine", "David Given", "FluxEngine integration") +{ + // hex::log::debug("Using romfs: '{}'", romfs::name()); + hex::LocalizationManager::addLanguages(romfs::get("lang/languages.json").string(), [](const std::filesystem::path &path) { + return romfs::get(path).string(); + }); + + hex::ContentRegistry::Provider::add(true); +} diff --git a/src/gui2/rsrc/empty.txt b/src/gui2/rsrc/empty.txt new file mode 100644 index 00000000..e69de29b