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/plugins.h | 91 +++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 50 deletions(-) (limited to 'primedev/plugins/plugins.h') diff --git a/primedev/plugins/plugins.h b/primedev/plugins/plugins.h index 4e841f27..d004038c 100644 --- a/primedev/plugins/plugins.h +++ b/primedev/plugins/plugins.h @@ -1,59 +1,50 @@ #pragma once -#include "plugin_abi.h" - -const int IDR_RCDATA1 = 101; +#include "core/sourceinterface.h" +#include "plugins/interfaces/interface.h" +#include "plugins/interfaces/IPluginId.h" +#include "plugins/interfaces/IPluginCallbacks.h" class Plugin { -public: - std::string name; - std::string displayName; - std::string dependencyName; - std::string description; - - std::string api_version; - std::string version; - - // For now this is just implemented as the index into the plugins array - // Maybe a bit shit but it works - int handle; +private: + CreateInterfaceFn m_pCreateInterface; + IPluginId* m_pluginId = 0; + IPluginCallbacks* m_callbacks = 0; - std::shared_ptr logger; + std::shared_ptr m_logger; - bool run_on_client = false; - bool run_on_server = false; + bool m_valid = false; + std::string m_name; + std::string m_logName; + std::string m_dependencyName; + std::string m_location; // path of the dll + bool m_runOnServer; + bool m_runOnClient; public: - PLUGIN_INIT_TYPE init; - PLUGIN_INIT_SQVM_TYPE init_sqvm_client; - PLUGIN_INIT_SQVM_TYPE init_sqvm_server; - PLUGIN_INFORM_SQVM_CREATED_TYPE inform_sqvm_created; - PLUGIN_INFORM_SQVM_DESTROYED_TYPE inform_sqvm_destroyed; - - PLUGIN_INFORM_DLL_LOAD_TYPE inform_dll_load; - - PLUGIN_RUNFRAME run_frame; + HMODULE m_handle; + PluginNorthstarData m_initData; + + Plugin(std::string path); + bool Unload() const; + void Reload() const; + + // sys + void Log(spdlog::level::level_enum level, char* msg) const; + + // callbacks + bool IsValid() const; + const std::string& GetName() const; + const std::string& GetLogName() const; + const std::string& GetDependencyName() const; + const std::string& GetLocation() const; + bool ShouldRunOnServer() const; + bool ShouldRunOnClient() const; + void* CreateInterface(const char* pName, int* pStatus) const; + void Init(bool reloaded) const; + void Finalize() const; + void OnSqvmCreated(CSquirrelVM* sqvm) const; + void OnSqvmDestroying(CSquirrelVM* sqvm) const; + void OnLibraryLoaded(HMODULE module, const char* name) const; + void RunFrame() const; }; - -class PluginManager -{ -public: - std::vector m_vLoadedPlugins; - -public: - bool LoadPlugins(); - std::optional LoadPlugin(fs::path path, PluginInitFuncs* funcs, PluginNorthstarData* data); - - void InformSQVMLoad(ScriptContext context, SquirrelFunctions* s); - void InformSQVMCreated(ScriptContext context, CSquirrelVM* sqvm); - void InformSQVMDestroyed(ScriptContext context); - - void InformDLLLoad(const char* dll, void* data, void* dllPtr); - - void RunFrame(); - -private: - std::string pluginPath; -}; - -extern PluginManager* g_pPluginManager; -- cgit v1.2.3