Build a more-or-less intact but non-functional plugin, due to C++

library differences.
This commit is contained in:
David Given
2025-08-31 19:21:01 +02:00
parent e4fd356254
commit 8ec96bcf71
4 changed files with 238 additions and 0 deletions

View File

@@ -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",
}
| (
{

123
src/gui2/build.py Normal file
View File

@@ -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"
],
)

114
src/gui2/plugin.cc Normal file
View File

@@ -0,0 +1,114 @@
#include <hex/plugin.hpp>
#include <hex/api/content_registry/provider.hpp>
#include <hex/api/imhex_api/provider.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/api/events/events_provider.hpp>
#include <nlohmann/json.hpp>
#include <romfs/romfs.hpp>
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<FluxEngineProvider>(true);
}

0
src/gui2/rsrc/empty.txt Normal file
View File