From edf013952ca2d110f190dc8cd16e5529846656e4 Mon Sep 17 00:00:00 2001 From: uniboi <64006268+uniboi@users.noreply.github.com> Date: Sun, 4 Feb 2024 02:14:46 +0100 Subject: Plugin interfaces (plugins v4) (#615) Replaces the current plugin api with source interfaces. - backwards compatible - no more json in binaries (wtf) - does not rely on structs from third party libraries (wtf) - actually initializes variables - no more basically unused classes The launcher exposes almost everything required by plugins in interfaces that allow for backwards compatibility. The only thing that's passed to a plugin directly is the northstar dll HWND and a struct of data that's different for each plugin. --- primedev/plugins/interfaces/sys/ISys.cpp | 66 ++++++++++++++++++++++++++++++++ primedev/plugins/interfaces/sys/ISys.h | 21 ++++++++++ 2 files changed, 87 insertions(+) create mode 100644 primedev/plugins/interfaces/sys/ISys.cpp create mode 100644 primedev/plugins/interfaces/sys/ISys.h (limited to 'primedev/plugins/interfaces/sys') diff --git a/primedev/plugins/interfaces/sys/ISys.cpp b/primedev/plugins/interfaces/sys/ISys.cpp new file mode 100644 index 00000000..6b0b41dd --- /dev/null +++ b/primedev/plugins/interfaces/sys/ISys.cpp @@ -0,0 +1,66 @@ +#include "plugins/interfaces/interface.h" +#include "ISys.h" +#include "plugins/plugins.h" +#include "plugins/pluginmanager.h" + +class CSys : public ISys +{ +public: + void Log(HMODULE handle, LogLevel level, char* msg) + { + spdlog::level::level_enum spdLevel; + + switch (level) + { + case LogLevel::WARN: + spdLevel = spdlog::level::level_enum::warn; + break; + case LogLevel::ERR: + spdLevel = spdlog::level::level_enum::err; + break; + default: + NS::log::PLUGINSYS->warn("Attempted to log with invalid level {}. Defaulting to info", (int)level); + case LogLevel::INFO: + spdLevel = spdlog::level::level_enum::info; + break; + } + + std::optional plugin = g_pPluginManager->GetPlugin(handle); + if (plugin) + { + plugin->Log(spdLevel, msg); + } + else + { + NS::log::PLUGINSYS->warn("Attempted to log message '{}' with invalid plugin handle {}", msg, static_cast(handle)); + } + } + + void Unload(HMODULE handle) + { + std::optional plugin = g_pPluginManager->GetPlugin(handle); + if (plugin) + { + plugin->Unload(); + } + else + { + NS::log::PLUGINSYS->warn("Attempted to unload plugin with invalid handle {}", static_cast(handle)); + } + } + + void Reload(HMODULE handle) + { + std::optional plugin = g_pPluginManager->GetPlugin(handle); + if (plugin) + { + plugin->Reload(); + } + else + { + NS::log::PLUGINSYS->warn("Attempted to reload plugin with invalid handle {}", static_cast(handle)); + } + } +}; + +EXPOSE_SINGLE_INTERFACE(CSys, ISys, SYS_VERSION); diff --git a/primedev/plugins/interfaces/sys/ISys.h b/primedev/plugins/interfaces/sys/ISys.h new file mode 100644 index 00000000..3e55a6d9 --- /dev/null +++ b/primedev/plugins/interfaces/sys/ISys.h @@ -0,0 +1,21 @@ +#ifndef ILOGGING_H +#define ILOGGING_H + +#define SYS_VERSION "NSSys001" + +enum class LogLevel : int +{ + INFO = 0, + WARN, + ERR, +}; + +class ISys +{ +public: + virtual void Log(HMODULE handle, LogLevel level, char* msg) = 0; + virtual void Unload(HMODULE handle) = 0; + virtual void Reload(HMODULE handle) = 0; +}; + +#endif -- cgit v1.2.3