aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-07 02:49:47 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-07 02:49:47 +0000
commitb6a5b5fca9b2315cdf8f26f10f9399b873964c9f (patch)
tree1ab1bce328c0b9737defb80706c63b8d9cf641f7 /NorthstarDedicatedTest
parent365191707407566841c1e37935619d260a4f67a7 (diff)
downloadNorthstarLauncher-b6a5b5fca9b2315cdf8f26f10f9399b873964c9f.tar.gz
NorthstarLauncher-b6a5b5fca9b2315cdf8f26f10f9399b873964c9f.zip
early pdiff support and vpk file compilation newline fix
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/keyvalues.cpp4
-rw-r--r--NorthstarDedicatedTest/pdef.cpp95
-rw-r--r--NorthstarDedicatedTest/playlist.cpp1
-rw-r--r--NorthstarDedicatedTest/scriptsrson.cpp2
4 files changed, 97 insertions, 5 deletions
diff --git a/NorthstarDedicatedTest/keyvalues.cpp b/NorthstarDedicatedTest/keyvalues.cpp
index cada5cbe..6de93822 100644
--- a/NorthstarDedicatedTest/keyvalues.cpp
+++ b/NorthstarDedicatedTest/keyvalues.cpp
@@ -113,11 +113,11 @@ void ModManager::TryBuildKeyValues(const char* filename)
newKvs += rootName;
newKvs += "\n{\n}\n";
- std::ofstream originalFileWriteStream(compiledDir / ogFilePath);
+ std::ofstream originalFileWriteStream(compiledDir / ogFilePath, std::ios::binary);
originalFileWriteStream << originalFile;
originalFileWriteStream.close();
- std::ofstream writeStream(compiledPath);
+ std::ofstream writeStream(compiledPath, std::ios::binary);
writeStream << newKvs;
writeStream.close();
diff --git a/NorthstarDedicatedTest/pdef.cpp b/NorthstarDedicatedTest/pdef.cpp
index 75ce3656..1fc7465f 100644
--- a/NorthstarDedicatedTest/pdef.cpp
+++ b/NorthstarDedicatedTest/pdef.cpp
@@ -3,11 +3,102 @@
#include "filesystem.h"
#include "hookutils.h"
#include "pdef.h"
+#include <map>
+#include <sstream>
+#include <fstream>
void ModManager::BuildPdef()
{
spdlog::info("Building persistent_player_data_version_231.pdef...");
- std::string originalPdef = ReadVPKOriginalFile(VPK_PDEF_PATH);
- spdlog::info(originalPdef);
+ fs::remove(MOD_PDEF_PATH);
+ std::string pdef = ReadVPKOriginalFile(VPK_PDEF_PATH);
+
+ for (Mod& mod : m_loadedMods)
+ {
+ if (!mod.Enabled || !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.compare(start, 2, "//") || end < 1)
+ continue;
+
+ if (inEnum)
+ {
+ if (!currentLine.compare(start, 9, "$ENUM_END"))
+ inEnum = false;
+ else
+ {
+ std::string enumMember = currentLine.substr(start, currentLine.size() - end - start);
+ // seek to first whitespace, just in case
+ int whitespaceIdx = 0;
+ for (; whitespaceIdx < enumMember.size(); whitespaceIdx++)
+ if (enumMember[whitespaceIdx] == ' ' || enumMember[whitespaceIdx] == '\t')
+ break;
+
+ enumAdds[currentEnum].push_back(enumMember.substr(0, whitespaceIdx));
+ }
+ }
+ 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";
+ }
+ }
+
+ // todo: enum stuff
+
+ }
+
+ fs::create_directories(MOD_PDEF_PATH.parent_path());
+
+ std::ofstream writeStream(MOD_PDEF_PATH, std::ios::binary);
+ writeStream << pdef;
+ writeStream.close();
+
+ ModOverrideFile overrideFile;
+ overrideFile.owningMod = nullptr;
+ overrideFile.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;
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/playlist.cpp b/NorthstarDedicatedTest/playlist.cpp
index 096f4f3d..1343ed40 100644
--- a/NorthstarDedicatedTest/playlist.cpp
+++ b/NorthstarDedicatedTest/playlist.cpp
@@ -21,6 +21,7 @@ void SetPlaylistCommand(const CCommand& args)
void SetPlaylistVarOverrideCommand(const CCommand& args)
{
+ // this is broken lol
if (args.ArgC() < 3)
return;
diff --git a/NorthstarDedicatedTest/scriptsrson.cpp b/NorthstarDedicatedTest/scriptsrson.cpp
index dbe4ddc1..d75a9e70 100644
--- a/NorthstarDedicatedTest/scriptsrson.cpp
+++ b/NorthstarDedicatedTest/scriptsrson.cpp
@@ -48,7 +48,7 @@ void ModManager::BuildScriptsRson()
fs::create_directories(MOD_SCRIPTS_RSON_PATH.parent_path());
- std::ofstream writeStream(MOD_SCRIPTS_RSON_PATH);
+ std::ofstream writeStream(MOD_SCRIPTS_RSON_PATH, std::ios::binary);
writeStream << scriptsRson;
writeStream.close();