Skip to content

Commit f45a618

Browse files
committed
fix(unload): Crashes
1 parent ed6e4e1 commit f45a618

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/core/entrypoint.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ SH_DECL_HOOK8_void(IGameEventSystem, PostEventAbstract, SH_NOATTRIB, 0, CSplitSc
7878
SH_DECL_HOOK3(IVEngineServer2, SetClientListening, SH_NOATTRIB, 0, bool, CPlayerSlot, CPlayerSlot, bool);
7979
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, CPlayerSlot, const CCommand&);
8080

81+
bool shuttingDown = false;
82+
8183
//////////////////////////////////////////////////////////////
8284
///////////////// Core Variables & Functions //////////////
8385
////////////////////////////////////////////////////////////
@@ -216,6 +218,8 @@ bool SwiftlyS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, boo
216218

217219
bool SwiftlyS2::Unload(char* error, size_t maxlen)
218220
{
221+
shuttingDown = true;
222+
219223
g_pluginManager.StopPlugins(false);
220224
g_pluginManager.UnloadPlugins();
221225

src/memory/hooks/functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ void FunctionHook::Initialize()
6161
hookFunc->addCallback(m_callbackType, m_handler);
6262
}
6363

64+
extern bool shuttingDown;
65+
6466
FunctionHook::~FunctionHook()
6567
{
6668
Disable();
6769
if (!m_pfn) return;
6870

71+
if (shuttingDown) return;
72+
6973
dyno::IHookManager& manager = dyno::IHookManager::Get();
7074
manager.unhookDetour(m_pfn);
7175
}

src/memory/hooks/vfunctions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ VFunctionHook::VFunctionHook(std::string library, std::string vtable, std::strin
2424
m_function_return = function_return;
2525
}
2626

27+
extern bool shuttingDown;
28+
2729
VFunctionHook::~VFunctionHook()
2830
{
2931
Disable();
3032
if (!m_pvtable) return;
3133

34+
if (shuttingDown) return;
35+
3236
dyno::IHookManager& manager = dyno::IHookManager::Get();
3337
manager.unhookVirtual(m_pvtable, m_ioffset);
3438
}

src/plugins/manager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ void PluginsManager::UnloadPlugin(std::string plugin_name)
9797

9898
for (auto it = pluginsList.begin(); it != pluginsList.end(); ++it)
9999
{
100-
if ((*it)->GetName() == plugin_name)
100+
if ((*it)->GetName() == plugin_name) {
101+
delete (*it);
101102
pluginsList.erase(it);
103+
break;
104+
}
102105
}
103106

104107
pluginsMap.erase(plugin_name);

0 commit comments

Comments
 (0)