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

Unloading CLEO plugins. #185

Merged
merged 4 commits into from
Sep 11, 2024
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
1 change: 1 addition & 0 deletions cleo_plugins/Audio/CSoundSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace CLEO

CSoundSystem::~CSoundSystem()
{
TRACE(""); // seaprator
TRACE("Finalizing SoundSystem...");
Clear();

Expand Down
6 changes: 4 additions & 2 deletions source/CCustomOpcodeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ namespace CLEO
void Init();
~CCustomOpcodeSystem()
{
TRACE("Last opcode executed: %04X", lastOpcode);
TRACE("Previous opcode executed: %04X", prevOpcode);
TRACE(""); // separator
TRACE("Custom Opcode System finalized:");
TRACE(" Last opcode executed: %04X", lastOpcode);
TRACE(" Previous opcode executed: %04X", prevOpcode);
}

static bool RegisterOpcode(WORD opcode, CustomOpcodeHandler callback);
Expand Down
1 change: 1 addition & 0 deletions source/CDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CDebug

~CDebug()
{
CLEO::Trace(CLEO::eLogLevel::Default, ""); // separator
CLEO::Trace(CLEO::eLogLevel::Default, "Log finished.");
}

Expand Down
21 changes: 19 additions & 2 deletions source/CPluginSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace CLEO;

CPluginSystem::~CPluginSystem()
{
std::for_each(plugins.begin(), plugins.end(), FreeLibrary);
UnloadPlugins();
}

void CPluginSystem::LoadPlugins()
Expand Down Expand Up @@ -79,7 +79,7 @@ void CPluginSystem::LoadPlugins()
continue;
}

plugins.push_back(hlib);
plugins.emplace_back(filename, hlib);
}
TRACE(""); // separator
}
Expand All @@ -91,6 +91,23 @@ void CPluginSystem::LoadPlugins()
pluginsLoaded = true;
}

void CPluginSystem::UnloadPlugins()
{
if (!pluginsLoaded) return;

TRACE(""); // separator
TRACE("Unloading CLEO plugins:");
for (const auto& plugin : plugins)
{
TRACE(" - Unloading '%s' at 0x%08X", plugin.name.c_str(), plugin.handle);
FreeLibrary(plugin.handle);
}
TRACE("CLEO plugins unloaded");

plugins.clear();
pluginsLoaded = false;
}

size_t CPluginSystem::GetNumPlugins() const
{
return plugins.size();
Expand Down
13 changes: 11 additions & 2 deletions source/CPluginSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
#include "FileEnumerator.h"
#include "CDebug.h"
#include <windows.h>
#include <algorithm>
#include <list>
#include <string>
#include <CMenuSystem.h>


namespace CLEO
{
class CPluginSystem
{
std::list<HMODULE> plugins;
struct PluginEntry
{
std::string name;
HMODULE handle = nullptr;

PluginEntry() = default;
PluginEntry(std::string name, HMODULE handle) : name(name), handle(handle) {}
};
std::list<PluginEntry> plugins;
bool pluginsLoaded = false;

public:
Expand All @@ -20,6 +28,7 @@ namespace CLEO
~CPluginSystem();

void LoadPlugins();
void UnloadPlugins();
size_t GetNumPlugins() const;
};
}
1 change: 1 addition & 0 deletions source/CScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ namespace CLEO

void CScriptEngine::LoadCustomScripts()
{
TRACE(""); // separator
TRACE("Listing CLEO scripts:");

std::set<std::string> found;
Expand Down
2 changes: 2 additions & 0 deletions source/CleoBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ namespace CLEO
m_bStarted = false;

ScriptEngine.GameEnd();

PluginSystem.UnloadPlugins();
}

void CCleoInstance::GameBegin()
Expand Down