From 2c02e7bc6a8055c5950a5ec8cb2fb40c6513436b Mon Sep 17 00:00:00 2001 From: Glacir <122596880+Glacir@users.noreply.github.com> Date: Mon, 30 Jan 2023 18:44:16 +0800 Subject: Format content of `enabledmods.json` (#406) Format enabledmods.json --- NorthstarDLL/mods/modmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp index 6310b7ec..a47aa854 100644 --- a/NorthstarDLL/mods/modmanager.cpp +++ b/NorthstarDLL/mods/modmanager.cpp @@ -11,7 +11,7 @@ #include "rapidjson/error/en.h" #include "rapidjson/document.h" #include "rapidjson/ostreamwrapper.h" -#include "rapidjson/writer.h" +#include "rapidjson/prettywriter.h" #include #include #include @@ -750,7 +750,7 @@ void ModManager::UnloadMods() std::ofstream writeStream(GetNorthstarPrefix() + "/enabledmods.json"); rapidjson::OStreamWrapper writeStreamWrapper(writeStream); - rapidjson::Writer writer(writeStreamWrapper); + rapidjson::PrettyWriter writer(writeStreamWrapper); m_EnabledModsCfg.Accept(writer); // do we need to dealloc individual entries in m_loadedMods? idk, rework -- cgit v1.2.3 From d418217e0ac6ada2217d5e5171f6baa3707380c9 Mon Sep 17 00:00:00 2001 From: Rémy Raes Date: Mon, 30 Jan 2023 11:44:37 +0100 Subject: feat: Remote mods directory (#403) * feat: create remote mod directory * feat: look for mods in remote mods directory --- NorthstarDLL/mods/modmanager.cpp | 15 ++++++++++++--- NorthstarDLL/mods/modmanager.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp index a47aa854..38966236 100644 --- a/NorthstarDLL/mods/modmanager.cpp +++ b/NorthstarDLL/mods/modmanager.cpp @@ -354,6 +354,7 @@ void ModManager::LoadMods() // ensure dirs exist fs::remove_all(GetCompiledAssetsPath()); fs::create_directories(GetModFolderPath()); + fs::create_directories(GetRemoteModFolderPath()); m_DependencyConstants.clear(); @@ -374,9 +375,13 @@ void ModManager::LoadMods() } // get mod directories - for (fs::directory_entry dir : fs::directory_iterator(GetModFolderPath())) - if (fs::exists(dir.path() / "mod.json")) - modDirs.push_back(dir.path()); + std::filesystem::directory_iterator classicModsDir = fs::directory_iterator(GetModFolderPath()); + std::filesystem::directory_iterator remoteModsDir = fs::directory_iterator(GetRemoteModFolderPath()); + + for (std::filesystem::directory_iterator modIterator : {classicModsDir, remoteModsDir}) + for (fs::directory_entry dir : modIterator) + if (fs::exists(dir.path() / "mod.json")) + modDirs.push_back(dir.path()); for (fs::path modDir : modDirs) { @@ -805,6 +810,10 @@ fs::path GetModFolderPath() { return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX); } +fs::path GetRemoteModFolderPath() +{ + return fs::path(GetNorthstarPrefix() + REMOTE_MOD_FOLDER_SUFFIX); +} fs::path GetCompiledAssetsPath() { return fs::path(GetNorthstarPrefix() + COMPILED_ASSETS_SUFFIX); diff --git a/NorthstarDLL/mods/modmanager.h b/NorthstarDLL/mods/modmanager.h index ded6ff06..c2335d09 100644 --- a/NorthstarDLL/mods/modmanager.h +++ b/NorthstarDLL/mods/modmanager.h @@ -161,6 +161,7 @@ class ModManager }; fs::path GetModFolderPath(); +fs::path GetRemoteModFolderPath(); fs::path GetCompiledAssetsPath(); extern ModManager* g_pModManager; -- cgit v1.2.3 From f7b7de8a584b877b9bf05fe63a0b0f91c7a5e944 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Wed, 1 Feb 2023 20:25:45 +0000 Subject: Allow `launchplaylist` to be used to start dedicated servers (#409) allow launchplaylist to be used to start dedicated servers --- NorthstarDLL/dedicated/dedicated.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NorthstarDLL/dedicated/dedicated.cpp b/NorthstarDLL/dedicated/dedicated.cpp index 33a3f034..8f6f8fe6 100644 --- a/NorthstarDLL/dedicated/dedicated.cpp +++ b/NorthstarDLL/dedicated/dedicated.cpp @@ -48,9 +48,9 @@ void RunServer(CDedicatedExports* dedicated) // initialise engine g_pEngine->Frame(); - // add +map if not present + // add +map if no map loading command is present // don't manually execute this from cbuf as users may have it in their startup args anyway, easier just to run from stuffcmds if present - if (!Tier0::CommandLine()->CheckParm("+map")) + if (!Tier0::CommandLine()->CheckParm("+map") && !Tier0::CommandLine()->CheckParm("+launchplaylist")) Tier0::CommandLine()->AppendParm("+map", g_pCVar->FindVar("match_defaultMap")->GetString()); // re-run commandline -- cgit v1.2.3 From 31a05c35e60b844cf806b146a4889f79272ed749 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Mon, 6 Feb 2023 00:25:06 +0000 Subject: Flush loggers properly on dedicated server shutdown (#413) flush loggers properly on dedicated server shutdown --- NorthstarDLL/dedicated/dedicated.cpp | 3 +++ NorthstarDLL/logging/crashhandler.cpp | 2 ++ NorthstarDLL/logging/logging.cpp | 8 ++++++++ NorthstarDLL/logging/logging.h | 2 ++ 4 files changed, 15 insertions(+) diff --git a/NorthstarDLL/dedicated/dedicated.cpp b/NorthstarDLL/dedicated/dedicated.cpp index 8f6f8fe6..3d7d756c 100644 --- a/NorthstarDLL/dedicated/dedicated.cpp +++ b/NorthstarDLL/dedicated/dedicated.cpp @@ -278,7 +278,10 @@ void, __fastcall, (void* sqvm)) // atm, this will crash if not aborted, so this just closes more gracefully static ConVar* Cvar_fatal_script_errors = g_pCVar->FindVar("fatal_script_errors"); if (Cvar_fatal_script_errors->GetBool()) + { + NS::log::FlushLoggers(); abort(); + } } ON_DLL_LOAD_DEDI("server.dll", DedicatedServerGameDLL, (CModule module)) diff --git a/NorthstarDLL/logging/crashhandler.cpp b/NorthstarDLL/logging/crashhandler.cpp index d4a54169..1e9bf4b3 100644 --- a/NorthstarDLL/logging/crashhandler.cpp +++ b/NorthstarDLL/logging/crashhandler.cpp @@ -72,6 +72,8 @@ void PrintExceptionLog(ExceptionLog& exc) "Northstar has crashed! Crash info can be found in R2Northstar/logs", "Northstar has crashed!", MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); + + NS::log::FlushLoggers(); } std::string GetExceptionName(ExceptionLog& exc) diff --git a/NorthstarDLL/logging/logging.cpp b/NorthstarDLL/logging/logging.cpp index 6bb57170..8b906911 100644 --- a/NorthstarDLL/logging/logging.cpp +++ b/NorthstarDLL/logging/logging.cpp @@ -203,3 +203,11 @@ void InitialiseLogging() loggers.push_back(NS::log::rpak); loggers.push_back(NS::log::echo); } + +void NS::log::FlushLoggers() +{ + for (auto& logger : loggers) + logger->flush(); + + spdlog::default_logger()->flush(); +} diff --git a/NorthstarDLL/logging/logging.h b/NorthstarDLL/logging/logging.h index b710915e..2cccdde6 100644 --- a/NorthstarDLL/logging/logging.h +++ b/NorthstarDLL/logging/logging.h @@ -100,6 +100,8 @@ namespace NS::log extern std::shared_ptr echo; extern std::shared_ptr NORTHSTAR; + + void FlushLoggers(); }; // namespace NS::log void RegisterCustomSink(std::shared_ptr sink); -- cgit v1.2.3 From b77baa4d09dae917c3fc9f9fc7d6b37c8d3c5205 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Tue, 7 Feb 2023 01:02:30 +0000 Subject: Do not load streaming files on dedicated server (#412) dont load streaming files on dedicated server --- NorthstarDLL/core/filesystem/rpakfilesystem.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NorthstarDLL/core/filesystem/rpakfilesystem.cpp b/NorthstarDLL/core/filesystem/rpakfilesystem.cpp index b46218e0..c3463781 100644 --- a/NorthstarDLL/core/filesystem/rpakfilesystem.cpp +++ b/NorthstarDLL/core/filesystem/rpakfilesystem.cpp @@ -267,6 +267,9 @@ void*, __fastcall, (const char* pPath, void* pCallback)) if (path.extension() == ".stbsp") { + if (IsDedicatedServer()) + return nullptr; + NS::log::rpak->info("LoadStreamBsp: {}", filename.string()); // resolve modded stbsp path so we can load mod stbsps @@ -279,6 +282,9 @@ void*, __fastcall, (const char* pPath, void* pCallback)) } else if (path.extension() == ".starpak") { + if (IsDedicatedServer()) + return nullptr; + // code for this is mostly stolen from above // unfortunately I can't find a way to get the rpak that is causing this function call, so I have to -- cgit v1.2.3 From b61ed18a86ddd2d7ab0e80992859750a49a9c4f6 Mon Sep 17 00:00:00 2001 From: Erlite Date: Thu, 9 Feb 2023 01:44:44 +0100 Subject: Add Destroy callback for squirrel scripts. (#383) * Add Destroy callback for squirrel scripts. * Switch _call() to Call() --- NorthstarDLL/mods/modmanager.cpp | 9 +++++++++ NorthstarDLL/mods/modmanager.h | 2 ++ NorthstarDLL/squirrel/squirrel.cpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) 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 void SquirrelManager::VMCreated(CSquir template void SquirrelManager::VMDestroyed() { + // Call all registered mod Destroy callbacks. + if (g_pModManager) + { + NS::log::squirrel_logger()->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()->info("Executed Destroy callback {}.", callback.DestroyCallback); + } + } + } + } + + // Discard the previous vm and delete the message buffer. m_pSQVM = nullptr; + + delete g_pSquirrel->messageBuffer; + g_pSquirrel->messageBuffer = nullptr; } template void SquirrelManager::ExecuteCode(const char* pCode) -- cgit v1.2.3