Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load plugin dependencies from lib folder #590

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions NorthstarDLL/plugins/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ std::optional<Plugin> PluginManager::LoadPlugin(fs::path path, PluginInitFuncs*
}
// Passed all checks, going to actually load it now

HMODULE pluginLib = LoadLibraryW(wpptr); // Load the DLL as a data file
HMODULE pluginLib =
LoadLibraryExW(wpptr, 0, LOAD_LIBRARY_SEARCH_USER_DIRS | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); // Load the DLL with lib folders
if (pluginLib == NULL)
{
NS::log::PLUGINSYS->info("Failed to load library '{}': ", std::system_category().message(GetLastError()));
Expand Down Expand Up @@ -197,7 +198,7 @@ inline void FindPlugins(fs::path pluginPath, std::vector<fs::path>& paths)
return;
}

for (const fs::directory_entry& entry : fs::recursive_directory_iterator(pluginPath))
for (const fs::directory_entry& entry : fs::directory_iterator(pluginPath))
{
if (fs::is_regular_file(entry) && entry.path().extension() == ".dll")
paths.emplace_back(entry.path());
Expand Down Expand Up @@ -229,6 +230,10 @@ bool PluginManager::LoadPlugins()
data.version = ns_version.c_str();
data.northstarModule = g_NorthstarModule;

fs::path libPath = fs::absolute(pluginPath + "\\lib");
if (fs::exists(libPath) && fs::is_directory(libPath))
AddDllDirectory(libPath.wstring().c_str());

FindPlugins(pluginPath, paths);

// Special case for Thunderstore mods dir
Expand All @@ -244,6 +249,11 @@ bool PluginManager::LoadPlugins()
spdlog::warn("The following directory did not match 'AUTHOR-MOD-VERSION': {}", dir.path().string());
continue; // skip loading package that doesn't match
}

fs::path libDir = fs::absolute(pluginsDir / "lib");
if (fs::exists(libDir) && fs::is_directory(libDir))
AddDllDirectory(libDir.wstring().c_str());

FindPlugins(pluginsDir, paths);
}

Expand Down