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

Add unload and load commands for plugins #836

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions primedev/plugins/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,28 @@ void ConCommand_reload_plugins(const CCommand& args)
g_pPluginManager->ReloadPlugins();
}

void ConCommand_unload_plugins(const CCommand& args)
{
for (const Plugin& plugin : g_pPluginManager->GetLoadedPlugins() | std::views::reverse)
{
std::string name = plugin.GetName();

if (args.ArgC() >= 2 && !strcmp(name.c_str(), args.Arg(1)))
continue;

if (plugin.Unload())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be wise to print if unloading fails, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it be wise to add a log call there

NS::log::PLUGINSYS->info("Unloaded {}", name);
}
}

void ConCommand_load_plugins(const CCommand& args)
{
g_pPluginManager->LoadPlugins();
}

ON_DLL_LOAD_RELIESON("engine.dll", PluginManager, ConCommand, (CModule module))
{
RegisterConCommand("reload_plugins", ConCommand_reload_plugins, "reloads plugins", FCVAR_NONE);
RegisterConCommand("unload_plugins", ConCommand_unload_plugins, "unloads plugins or a single plugin", FCVAR_NONE);
RegisterConCommand("load_plugins", ConCommand_load_plugins, "loads plugins", FCVAR_NONE);
}