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

Fix reloading plugins #835

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions primedev/plugins/pluginmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "pluginmanager.h"

#include <regex>
#include <ranges>
#include "plugins.h"
#include "config/profile.h"
#include "core/convar/concommand.h"
Expand Down Expand Up @@ -111,13 +112,14 @@ bool PluginManager::LoadPlugins(bool reloaded)

void PluginManager::ReloadPlugins()
{
for (const Plugin& plugin : this->GetLoadedPlugins())
NS::log::PLUGINSYS->info("Reloading plugins");

for (const Plugin& plugin : this->plugins | std::views::reverse)
{
plugin.Unload();
std::string name = plugin.GetName();
if (plugin.Reload())
NS::log::PLUGINSYS->info("Reloaded {}", name);
}

this->plugins.clear();
this->LoadPlugins(true);
}

void PluginManager::RemovePlugin(HMODULE handle)
Expand Down
14 changes: 9 additions & 5 deletions primedev/plugins/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ bool Plugin::Unload() const

if (IsValid())
{
bool unloaded = m_callbacks->Unload();
bool shouldUnload = m_callbacks->Unload();

if (!unloaded)
if (!shouldUnload)
return false;
}

Expand All @@ -154,14 +154,18 @@ bool Plugin::Unload() const
return true;
}

void Plugin::Reload() const
bool Plugin::Reload() const
{
std::string location = m_location;

bool unloaded = Unload();

if (!unloaded)
return;
return false;

g_pPluginManager->LoadPlugin(fs::path(m_location), true);
g_pPluginManager->LoadPlugin(fs::path(location), true);

return true;
}

void Plugin::Log(spdlog::level::level_enum level, char* msg) const
Expand Down
2 changes: 1 addition & 1 deletion primedev/plugins/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Plugin

Plugin(std::string path);
bool Unload() const;
void Reload() const;
bool Reload() const;

// sys
void Log(spdlog::level::level_enum level, char* msg) const;
Expand Down
Loading