aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/mods/compiled
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 /NorthstarDLL/mods/compiled
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 'NorthstarDLL/mods/compiled')
-rw-r--r--NorthstarDLL/mods/compiled/kb_act.cpp44
-rw-r--r--NorthstarDLL/mods/compiled/modkeyvalues.cpp106
-rw-r--r--NorthstarDLL/mods/compiled/modpdef.cpp118
-rw-r--r--NorthstarDLL/mods/compiled/modscriptsrson.cpp65
4 files changed, 0 insertions, 333 deletions
diff --git a/NorthstarDLL/mods/compiled/kb_act.cpp b/NorthstarDLL/mods/compiled/kb_act.cpp
deleted file mode 100644
index 6117fd28..00000000
--- a/NorthstarDLL/mods/compiled/kb_act.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#include "mods/modmanager.h"
-#include "core/filesystem/filesystem.h"
-
-#include <fstream>
-
-const char* KB_ACT_PATH = "scripts\\kb_act.lst";
-
-// compiles the file kb_act.lst, that defines entries for keybindings in the options menu
-void ModManager::BuildKBActionsList()
-{
- spdlog::info("Building kb_act.lst");
-
- fs::create_directories(GetCompiledAssetsPath() / "scripts");
- std::ofstream soCompiledKeys(GetCompiledAssetsPath() / KB_ACT_PATH, std::ios::binary);
-
- // write vanilla file's content to compiled file
- soCompiledKeys << ReadVPKOriginalFile(KB_ACT_PATH);
-
- for (Mod& mod : m_LoadedMods)
- {
- if (!mod.m_bEnabled)
- continue;
-
- // write content of each modded file to compiled file
- std::ifstream siModKeys(mod.m_ModDirectory / "kb_act.lst");
-
- if (siModKeys.good())
- soCompiledKeys << siModKeys.rdbuf() << std::endl;
-
- siModKeys.close();
- }
-
- soCompiledKeys.close();
-
- // push to overrides
- ModOverrideFile overrideFile;
- overrideFile.m_pOwningMod = nullptr;
- overrideFile.m_Path = KB_ACT_PATH;
-
- if (m_ModFiles.find(KB_ACT_PATH) == m_ModFiles.end())
- m_ModFiles.insert(std::make_pair(KB_ACT_PATH, overrideFile));
- else
- m_ModFiles[KB_ACT_PATH] = overrideFile;
-}
diff --git a/NorthstarDLL/mods/compiled/modkeyvalues.cpp b/NorthstarDLL/mods/compiled/modkeyvalues.cpp
deleted file mode 100644
index e44a81d3..00000000
--- a/NorthstarDLL/mods/compiled/modkeyvalues.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-#include "mods/modmanager.h"
-#include "core/filesystem/filesystem.h"
-
-#include <fstream>
-
-AUTOHOOK_INIT()
-
-void ModManager::TryBuildKeyValues(const char* filename)
-{
- spdlog::info("Building KeyValues for file {}", filename);
-
- std::string normalisedPath = g_pModManager->NormaliseModFilePath(fs::path(filename));
- fs::path compiledPath = GetCompiledAssetsPath() / filename;
- fs::path compiledDir = compiledPath.parent_path();
- fs::create_directories(compiledDir);
-
- fs::path kvPath(filename);
- std::string ogFilePath = "mod_original_";
- ogFilePath += kvPath.filename().string();
-
- std::string newKvs = "// AUTOGENERATED: MOD PATCH KV\n";
-
- int patchNum = 0;
-
- // copy over patch kv files, and add #bases to new file, last mods' patches should be applied first
- // note: #include should be identical but it's actually just broken, thanks respawn
- for (int64_t i = m_LoadedMods.size() - 1; i > -1; i--)
- {
- if (!m_LoadedMods[i].m_bEnabled)
- continue;
-
- size_t fileHash = STR_HASH(normalisedPath);
- auto modKv = m_LoadedMods[i].KeyValues.find(fileHash);
- if (modKv != m_LoadedMods[i].KeyValues.end())
- {
- // should result in smth along the lines of #include "mod_patch_5_mp_weapon_car.txt"
-
- std::string patchFilePath = "mod_patch_";
- patchFilePath += std::to_string(patchNum++);
- patchFilePath += "_";
- patchFilePath += kvPath.filename().string();
-
- newKvs += "#base \"";
- newKvs += patchFilePath;
- newKvs += "\"\n";
-
- fs::remove(compiledDir / patchFilePath);
-
- fs::copy_file(m_LoadedMods[i].m_ModDirectory / "keyvalues" / filename, compiledDir / patchFilePath);
- }
- }
-
- // add original #base last, #bases don't override preexisting keys, including the ones we've just done
- newKvs += "#base \"";
- newKvs += ogFilePath;
- newKvs += "\"\n";
-
- // load original file, so we can parse out the name of the root obj (e.g. WeaponData for weapons)
- std::string originalFile = ReadVPKOriginalFile(filename);
-
- if (!originalFile.length())
- {
- spdlog::warn("Tried to patch kv {} but no base kv was found!", ogFilePath);
- return;
- }
-
- char rootName[64];
- memset(rootName, 0, sizeof(rootName));
-
- // iterate until we hit an ascii char that isn't in a # command or comment to get root obj name
- int i = 0;
- while (!(originalFile[i] >= 65 && originalFile[i] <= 122))
- {
- // if we hit a comment or # thing, iterate until end of line
- if (originalFile[i] == '/' || originalFile[i] == '#')
- while (originalFile[i] != '\n')
- i++;
-
- i++;
- }
-
- int j = 0;
- for (int j = 0; originalFile[i] >= 65 && originalFile[i] <= 122; j++)
- rootName[j] = originalFile[i++];
-
- // empty kv, all the other stuff gets #base'd
- newKvs += rootName;
- newKvs += "\n{\n}\n";
-
- std::ofstream originalFileWriteStream(compiledDir / ogFilePath, std::ios::binary);
- originalFileWriteStream << originalFile;
- originalFileWriteStream.close();
-
- std::ofstream writeStream(compiledPath, std::ios::binary);
- writeStream << newKvs;
- writeStream.close();
-
- ModOverrideFile overrideFile;
- overrideFile.m_pOwningMod = nullptr;
- overrideFile.m_Path = normalisedPath;
-
- if (m_ModFiles.find(normalisedPath) == m_ModFiles.end())
- m_ModFiles.insert(std::make_pair(normalisedPath, overrideFile));
- else
- m_ModFiles[normalisedPath] = overrideFile;
-}
diff --git a/NorthstarDLL/mods/compiled/modpdef.cpp b/NorthstarDLL/mods/compiled/modpdef.cpp
deleted file mode 100644
index d268a063..00000000
--- a/NorthstarDLL/mods/compiled/modpdef.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-#include "mods/modmanager.h"
-#include "core/filesystem/filesystem.h"
-
-#include <map>
-#include <sstream>
-#include <fstream>
-
-const fs::path MOD_PDEF_SUFFIX = "cfg/server/persistent_player_data_version_231.pdef";
-const char* VPK_PDEF_PATH = "cfg/server/persistent_player_data_version_231.pdef";
-
-void ModManager::BuildPdef()
-{
- spdlog::info("Building persistent_player_data_version_231.pdef...");
-
- fs::path MOD_PDEF_PATH = fs::path(GetCompiledAssetsPath() / MOD_PDEF_SUFFIX);
-
- fs::remove(MOD_PDEF_PATH);
- std::string pdef = ReadVPKOriginalFile(VPK_PDEF_PATH);
-
- for (Mod& mod : m_LoadedMods)
- {
- if (!mod.m_bEnabled || !mod.Pdiff.size())
- continue;
-
- // this code probably isn't going to be pretty lol
- // refer to shared/pjson.js for an actual okish parser of the pdiff format
- // but pretty much, $ENUM_ADD blocks define members added to preexisting enums
- // $PROP_START ends the custom stuff, and from there it's just normal props we append to the pdef
-
- std::map<std::string, std::vector<std::string>> enumAdds;
-
- // read pdiff
- bool inEnum = false;
- bool inProp = false;
- std::string currentEnum;
- std::string currentLine;
- std::istringstream pdiffStream(mod.Pdiff);
-
- while (std::getline(pdiffStream, currentLine))
- {
- if (inProp)
- {
- // just append to pdef here
- pdef += currentLine;
- pdef += '\n';
- continue;
- }
-
- // trim leading whitespace
- size_t start = currentLine.find_first_not_of(" \n\r\t\f\v");
- size_t end = currentLine.find("//");
- if (end == std::string::npos)
- end = currentLine.size() - 1; // last char
-
- if (!currentLine.size() || !currentLine.compare(start, 2, "//"))
- continue;
-
- if (inEnum)
- {
- if (!currentLine.compare(start, 9, "$ENUM_END"))
- inEnum = false;
- else
- enumAdds[currentEnum].push_back(currentLine); // only need to push_back current line, if there's syntax errors then game
- // pdef parser will handle them
- }
- else if (!currentLine.compare(start, 9, "$ENUM_ADD"))
- {
- inEnum = true;
- currentEnum = currentLine.substr(start + 10 /*$ENUM_ADD + 1*/, currentLine.size() - end - (start + 10));
- enumAdds.insert(std::make_pair(currentEnum, std::vector<std::string>()));
- }
- else if (!currentLine.compare(start, 11, "$PROP_START"))
- {
- inProp = true;
- pdef += "\n// $PROP_START ";
- pdef += mod.Name;
- pdef += "\n";
- }
- }
-
- // add new members to preexisting enums
- // note: this code could 100% be messed up if people put //$ENUM_START comments and the like
- // could make it protect against this, but honestly not worth atm
- for (auto enumAdd : enumAdds)
- {
- std::string addStr;
- for (std::string enumMember : enumAdd.second)
- {
- addStr += enumMember;
- addStr += '\n';
- }
-
- // start of enum we're adding to
- std::string startStr = "$ENUM_START ";
- startStr += enumAdd.first;
-
- // insert enum values into enum
- size_t insertIdx = pdef.find("$ENUM_END", pdef.find(startStr));
- pdef.reserve(addStr.size());
- pdef.insert(insertIdx, addStr);
- }
- }
-
- fs::create_directories(MOD_PDEF_PATH.parent_path());
-
- std::ofstream writeStream(MOD_PDEF_PATH, std::ios::binary);
- writeStream << pdef;
- writeStream.close();
-
- ModOverrideFile overrideFile;
- overrideFile.m_pOwningMod = nullptr;
- overrideFile.m_Path = VPK_PDEF_PATH;
-
- if (m_ModFiles.find(VPK_PDEF_PATH) == m_ModFiles.end())
- m_ModFiles.insert(std::make_pair(VPK_PDEF_PATH, overrideFile));
- else
- m_ModFiles[VPK_PDEF_PATH] = overrideFile;
-}
diff --git a/NorthstarDLL/mods/compiled/modscriptsrson.cpp b/NorthstarDLL/mods/compiled/modscriptsrson.cpp
deleted file mode 100644
index d130745f..00000000
--- a/NorthstarDLL/mods/compiled/modscriptsrson.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#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
-}