summaryrefslogtreecommitdiff
path: root/ZAPD/ZFile.cpp
diff options
context:
space:
mode:
authorEllipticEllipsis <elliptic.ellipsis@gmail.com>2023-05-03 22:29:19 +0100
committerGitHub <noreply@github.com>2023-05-03 17:29:19 -0400
commitae0c2038007558d087418ff6ad2b3cd5e3cf6579 (patch)
treeb9f426cb9b1da4527f85046578efc8ba8cd9d7bb /ZAPD/ZFile.cpp
parentfcfa28901e91d756ad22f05e6827d7646e484061 (diff)
Defines for texture dimensions (#233)
* Create functions to produce and add defines to the header * Format * Fix Jenkinsfile * Make gcc shut up about fallthrough * Fix symbols that start with g but are not global
Diffstat (limited to 'ZAPD/ZFile.cpp')
-rw-r--r--ZAPD/ZFile.cpp61
1 files changed, 58 insertions, 3 deletions
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp
index f8b2707..8f9bfca 100644
--- a/ZAPD/ZFile.cpp
+++ b/ZAPD/ZFile.cpp
@@ -181,6 +181,12 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename)
}
}
+ const char* segmentDefines = reader->Attribute("Defines");
+ if (segmentDefines != NULL)
+ {
+ makeDefines = true;
+ }
+
if (mode == ZFileMode::Extract || mode == ZFileMode::ExternalFile)
{
if (!File::Exists((basePath / name).string()))
@@ -599,6 +605,43 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in
return decl;
}
+Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& includePath,
+ size_t size, const std::string& varType,
+ const std::string& varName,
+ const std::string& defines, size_t arrayItemCnt)
+{
+ bool validOffset = AddDeclarationChecks(address, varName);
+ if (!validOffset)
+ return nullptr;
+
+ if (StringHelper::StartsWith(includePath, "assets/extracted/"))
+ includePath = "assets/" + StringHelper::Split(includePath, "assets/extracted/")[1];
+ if (StringHelper::StartsWith(includePath, "assets/custom/"))
+ includePath = "assets/" + StringHelper::Split(includePath, "assets/custom/")[1];
+
+ Declaration* decl = GetDeclaration(address);
+ if (decl == nullptr)
+ {
+ decl = new Declaration(address, includePath, size, varType, varName, defines);
+
+ decl->isArray = true;
+ decl->arrayItemCnt = arrayItemCnt;
+
+ declarations[address] = decl;
+ }
+ else
+ {
+ decl->includePath = includePath;
+ decl->varType = varType;
+ decl->varName = varName;
+ decl->defines = defines;
+ decl->size = size;
+ decl->isArray = true;
+ decl->arrayItemCnt = arrayItemCnt;
+ }
+ return decl;
+}
+
bool ZFile::AddDeclarationChecks(uint32_t address, const std::string& varName)
{
assert(GETSEGNUM(address) == 0);
@@ -1090,7 +1133,8 @@ void ZFile::ProcessDeclarationText(Declaration* decl)
std::string ZFile::ProcessExterns()
{
- std::string output;
+ std::string output = "";
+ bool hadDefines = true; // Previous declaration included defines.
for (const auto& item : declarations)
{
@@ -1099,10 +1143,21 @@ std::string ZFile::ProcessExterns()
continue;
}
+ std::string itemDefines = item.second->GetDefinesStr();
+ // Add a newline above if previous has no defines and this one does.
+ if (!hadDefines && (itemDefines.length() > 0))
+ {
+ output.push_back('\n');
+ }
output += item.second->GetExternStr();
- }
+ output += itemDefines;
- output += "\n";
+ // Newline below if this one has defines.
+ if ((hadDefines = (itemDefines.length() > 0)))
+ {
+ output.push_back('\n');
+ }
+ }
output += defines;