aboutsummaryrefslogtreecommitdiff
path: root/primedev/mods/compiled/modscriptsrson.cpp
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2023-12-27 00:32:01 +0000
committerGitHub <noreply@github.com>2023-12-27 01:32:01 +0100
commitf5ab6fb5e8be7b73e6003d4145081d5e0c0ce287 (patch)
tree90f2c6a4885dbd181799e2325cf33588697674e1 /primedev/mods/compiled/modscriptsrson.cpp
parentbb8ed59f6891b1196c5f5bbe7346cd171c8215fa (diff)
downloadNorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.tar.gz
NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.zip
Folder restructuring from primedev (#624)v1.21.2-rc3v1.21.2
Copies of over the primedev folder structure for easier cherry-picking of further changes Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'primedev/mods/compiled/modscriptsrson.cpp')
-rw-r--r--primedev/mods/compiled/modscriptsrson.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/primedev/mods/compiled/modscriptsrson.cpp b/primedev/mods/compiled/modscriptsrson.cpp
new file mode 100644
index 00000000..d130745f
--- /dev/null
+++ b/primedev/mods/compiled/modscriptsrson.cpp
@@ -0,0 +1,65 @@
+#include "mods/modmanager.h"
+#include "core/filesystem/filesystem.h"
+#include "squirrel/squirrel.h"
+
+#include <fstream>
+
+const std::string MOD_SCRIPTS_RSON_SUFFIX = "scripts/vscripts/scripts.rson";
+const char* VPK_SCRIPTS_RSON_PATH = "scripts\\vscripts\\scripts.rson";
+
+void ModManager::BuildScriptsRson()
+{
+ spdlog::info("Building custom scripts.rson");
+ fs::path MOD_SCRIPTS_RSON_PATH = fs::path(GetCompiledAssetsPath() / MOD_SCRIPTS_RSON_SUFFIX);
+ fs::remove(MOD_SCRIPTS_RSON_PATH);
+
+ std::string scriptsRson = ReadVPKOriginalFile(VPK_SCRIPTS_RSON_PATH);
+ scriptsRson += "\n\n// START MODDED SCRIPT CONTENT\n\n"; // newline before we start custom stuff
+
+ for (Mod& mod : m_LoadedMods)
+ {
+ if (!mod.m_bEnabled)
+ continue;
+
+ // this isn't needed at all, just nice to have imo
+ scriptsRson += "// MOD: ";
+ scriptsRson += mod.Name;
+ scriptsRson += ":\n\n";
+
+ for (ModScript& script : mod.Scripts)
+ {
+ /* should create something with this format for each script
+ When: "CONTEXT"
+ Scripts:
+ [
+ _coolscript.gnut
+ ]*/
+
+ scriptsRson += "When: \"";
+ scriptsRson += script.RunOn;
+ scriptsRson += "\"\n";
+
+ scriptsRson += "Scripts:\n[\n\t";
+ scriptsRson += script.Path;
+ scriptsRson += "\n]\n\n";
+ }
+ }
+
+ fs::create_directories(MOD_SCRIPTS_RSON_PATH.parent_path());
+
+ std::ofstream writeStream(MOD_SCRIPTS_RSON_PATH, std::ios::binary);
+ writeStream << scriptsRson;
+ writeStream.close();
+
+ ModOverrideFile overrideFile;
+ overrideFile.m_pOwningMod = nullptr;
+ overrideFile.m_Path = VPK_SCRIPTS_RSON_PATH;
+
+ if (m_ModFiles.find(VPK_SCRIPTS_RSON_PATH) == m_ModFiles.end())
+ m_ModFiles.insert(std::make_pair(VPK_SCRIPTS_RSON_PATH, overrideFile));
+ else
+ m_ModFiles[VPK_SCRIPTS_RSON_PATH] = overrideFile;
+
+ // todo: for preventing dupe scripts in scripts.rson, we could actually parse when conditions with the squirrel vm, just need a way to
+ // get a result out of squirrelmanager.ExecuteCode this would probably be the best way to do this, imo
+}