aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/pdef.cpp
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-07 03:33:45 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-11-07 03:33:45 +0000
commit916f4f53ad839d6f8e565e50bb310429a3e115f3 (patch)
tree5f5a83e7dd37bf64a81b53d8a88c569e17372f72 /NorthstarDedicatedTest/pdef.cpp
parentb6a5b5fca9b2315cdf8f26f10f9399b873964c9f (diff)
downloadNorthstarLauncher-916f4f53ad839d6f8e565e50bb310429a3e115f3.tar.gz
NorthstarLauncher-916f4f53ad839d6f8e565e50bb310429a3e115f3.zip
add pdiff enum adds
Diffstat (limited to 'NorthstarDedicatedTest/pdef.cpp')
-rw-r--r--NorthstarDedicatedTest/pdef.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/NorthstarDedicatedTest/pdef.cpp b/NorthstarDedicatedTest/pdef.cpp
index 1fc7465f..83a31db0 100644
--- a/NorthstarDedicatedTest/pdef.cpp
+++ b/NorthstarDedicatedTest/pdef.cpp
@@ -49,7 +49,7 @@ void ModManager::BuildPdef()
if (end == std::string::npos)
end = currentLine.size() - 1; // last char
- if (!currentLine.compare(start, 2, "//") || end < 1)
+ if (!currentLine.size() || !currentLine.compare(start, 2, "//"))
continue;
if (inEnum)
@@ -57,16 +57,7 @@ void ModManager::BuildPdef()
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));
- }
+ 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"))
{
@@ -83,8 +74,27 @@ void ModManager::BuildPdef()
}
}
- // todo: enum stuff
+ // 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());