6#include <unordered_map>
11#define WIN32_LEAN_AND_MEAN
37 auto proc = GetProcAddress(hmod, name);
39 auto proc = dlsym(hmod, name);
43 throw std::runtime_error(std::string(
"Couldn't load function ") + name +
" from " + module_name);
45 return reinterpret_cast<F
>(proc);
47#define GetKnownProcAddress(plugins_map, plugin_name, func) GetKnownProcAddressImpl(plugins_map[plugin_name], plugin_name.c_str(), #func, func);
56 for (
const auto& f : std::filesystem::directory_iterator(
plugins_folder))
58 const std::string path_str = f.path().string();
60 plugins[path_str] = LoadLibraryA(path_str.c_str());
62 plugins[path_str] = dlopen(path_str.c_str(), RTLD_NOW);
66 throw std::runtime_error(
"Couldn't load plugin at " + path_str);
110 else if (!it->second.empty())
113 if (raw_ptr !=
nullptr)
124 std::unordered_map<std::string, HMODULE>
plugins;
126 std::unordered_map<std::string, void*>
plugins;
#define GetKnownProcAddress(plugins_map, plugin_name, func)
std::shared_ptr< PluginObject > CreatePluginObject(const char *identifier)
std::unordered_map< std::string, std::string > cached_identifier_to_plugin
std::unordered_map< std::string, std::function< void(PluginObject *)> > DestroyPluginObject_funcs
std::unordered_map< std::string, void * > plugins
std::unordered_map< std::string, std::function< PluginObject *(const char *)> > GetPluginObject_funcs
void(* DestroyPluginObject)(PluginObject *object)=0
F GetKnownProcAddressImpl(void *hmod, const char *module_name, const char *name, F)
PluginObject *(* GetPluginObject)(const char *identifier)=0
constexpr std::string_view plugins_folder
Folder in which the protocolCraft plugins will be searched for.
std::shared_ptr< PluginObject > CreateObjectFromPlugin(const char *identifier)
Create an abstract PluginObject using a runtime loaded plugin (dll/so)