diff options
Diffstat (limited to 'NorthstarDLL')
-rw-r--r-- | NorthstarDLL/mods/modmanager.cpp | 9 | ||||
-rw-r--r-- | NorthstarDLL/mods/modmanager.h | 2 | ||||
-rw-r--r-- | NorthstarDLL/squirrel/squirrel.cpp | 28 |
3 files changed, 39 insertions, 0 deletions
diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp index 38966236..e37df6e5 100644 --- a/NorthstarDLL/mods/modmanager.cpp +++ b/NorthstarDLL/mods/modmanager.cpp @@ -198,6 +198,9 @@ Mod::Mod(fs::path modDir, char* jsonBuf) if (scriptObj["ServerCallback"].HasMember("After") && scriptObj["ServerCallback"]["After"].IsString()) callback.AfterCallback = scriptObj["ServerCallback"]["After"].GetString(); + if (scriptObj["ServerCallback"].HasMember("Destroy") && scriptObj["ServerCallback"]["Destroy"].IsString()) + callback.DestroyCallback = scriptObj["ServerCallback"]["Destroy"].GetString(); + script.Callbacks.push_back(callback); } @@ -212,6 +215,9 @@ Mod::Mod(fs::path modDir, char* jsonBuf) if (scriptObj["ClientCallback"].HasMember("After") && scriptObj["ClientCallback"]["After"].IsString()) callback.AfterCallback = scriptObj["ClientCallback"]["After"].GetString(); + if (scriptObj["ClientCallback"].HasMember("Destroy") && scriptObj["ClientCallback"]["Destroy"].IsString()) + callback.DestroyCallback = scriptObj["ClientCallback"]["Destroy"].GetString(); + script.Callbacks.push_back(callback); } @@ -226,6 +232,9 @@ Mod::Mod(fs::path modDir, char* jsonBuf) if (scriptObj["UICallback"].HasMember("After") && scriptObj["UICallback"]["After"].IsString()) callback.AfterCallback = scriptObj["UICallback"]["After"].GetString(); + if (scriptObj["UICallback"].HasMember("Destroy") && scriptObj["UICallback"]["Destroy"].IsString()) + callback.DestroyCallback = scriptObj["UICallback"]["Destroy"].GetString(); + script.Callbacks.push_back(callback); } diff --git a/NorthstarDLL/mods/modmanager.h b/NorthstarDLL/mods/modmanager.h index c2335d09..369eb07b 100644 --- a/NorthstarDLL/mods/modmanager.h +++ b/NorthstarDLL/mods/modmanager.h @@ -41,6 +41,8 @@ struct ModScriptCallback std::string BeforeCallback; // called after the codecallback has finished executing std::string AfterCallback; + // called right before the vm is destroyed. + std::string DestroyCallback; }; struct ModScript 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) |