aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/squirrel/squirrel.cpp
diff options
context:
space:
mode:
authorErlite <ys.aameziane@gmail.com>2023-02-09 01:44:44 +0100
committerGitHub <noreply@github.com>2023-02-09 00:44:44 +0000
commitb61ed18a86ddd2d7ab0e80992859750a49a9c4f6 (patch)
treed8a3dc1230d8a1da8feda6d1f41980dfa5eab15e /NorthstarDLL/squirrel/squirrel.cpp
parentb77baa4d09dae917c3fc9f9fc7d6b37c8d3c5205 (diff)
downloadNorthstarLauncher-b61ed18a86ddd2d7ab0e80992859750a49a9c4f6.tar.gz
NorthstarLauncher-b61ed18a86ddd2d7ab0e80992859750a49a9c4f6.zip
Add Destroy callback for squirrel scripts. (#383)v1.12.3-rc2v1.12.3-rc1v1.12.3
* Add Destroy callback for squirrel scripts. * Switch _call() to Call()
Diffstat (limited to 'NorthstarDLL/squirrel/squirrel.cpp')
-rw-r--r--NorthstarDLL/squirrel/squirrel.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/NorthstarDLL/squirrel/squirrel.cpp b/NorthstarDLL/squirrel/squirrel.cpp
index 4771bf3f..25fb90d5 100644
--- a/NorthstarDLL/squirrel/squirrel.cpp
+++ b/NorthstarDLL/squirrel/squirrel.cpp
@@ -1,5 +1,6 @@
#include "pch.h"
#include "squirrel.h"
+#include "logging/logging.h"
#include "core/convar/concommand.h"
#include "mods/modmanager.h"
#include "dedicated/dedicated.h"
@@ -212,7 +213,34 @@ template <ScriptContext context> void SquirrelManager<context>::VMCreated(CSquir
template <ScriptContext context> void SquirrelManager<context>::VMDestroyed()
{
+ // Call all registered mod Destroy callbacks.
+ if (g_pModManager)
+ {
+ NS::log::squirrel_logger<context>()->info("Calling Destroy callbacks for all loaded mods.");
+
+ for (const Mod& loadedMod : g_pModManager->m_LoadedMods)
+ {
+ for (const ModScript& script : loadedMod.Scripts)
+ {
+ for (const ModScriptCallback& callback : script.Callbacks)
+ {
+ if (callback.Context != context || callback.DestroyCallback.length() == 0)
+ {
+ continue;
+ }
+
+ Call(callback.DestroyCallback.c_str());
+ NS::log::squirrel_logger<context>()->info("Executed Destroy callback {}.", callback.DestroyCallback);
+ }
+ }
+ }
+ }
+
+ // Discard the previous vm and delete the message buffer.
m_pSQVM = nullptr;
+
+ delete g_pSquirrel<context>->messageBuffer;
+ g_pSquirrel<context>->messageBuffer = nullptr;
}
template <ScriptContext context> void SquirrelManager<context>::ExecuteCode(const char* pCode)