1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-13 18:30:35 +00:00

git subrepo pull --force tools/ZAPD (#727)

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "4751db5c9"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "4751db5c9"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"
This commit is contained in:
fig02 2021-03-20 12:02:12 -04:00 committed by GitHub
parent 77ec4d4916
commit 493bdbc3c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
115 changed files with 16370 additions and 2789 deletions

105
tools/ZAPD/ZAPD/ZSymbol.cpp Normal file
View file

@ -0,0 +1,105 @@
#include "ZSymbol.h"
#include "StringHelper.h"
ZSymbol::ZSymbol(const std::string& nName, int nRawDataIndex, const std::string& nType,
uint32_t nTypeSize, bool nIsArray, uint32_t nCount)
: type(nType), typeSize(nTypeSize), isArray(nIsArray), count(nCount)
{
name = nName;
rawDataIndex = nRawDataIndex;
}
ZSymbol::ZSymbol(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
ParseXML(reader);
}
ZSymbol* ZSymbol::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* parent)
{
ZSymbol* symbol = new ZSymbol(reader, nRawData, nRawDataIndex, parent);
return symbol;
}
void ZSymbol::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
const char* typeXml = reader->Attribute("Type");
if (typeXml == nullptr)
{
fprintf(stderr,
"ZSymbol::ParseXML: Warning in '%s'.\n\t Missing 'Type' attribute in xml. "
"Defaulting to 'void*'.\n",
name.c_str());
type = "void*";
}
else
{
type = std::string(typeXml);
}
const char* typeSizeXml = reader->Attribute("TypeSize");
if (typeSizeXml == nullptr)
{
fprintf(stderr,
"ZSymbol::ParseXML: Warning in '%s'.\n\t Missing 'TypeSize' attribute in xml. "
"Defaulting to '4'.\n",
name.c_str());
typeSize = 4; // Size of a word.
}
else
{
typeSize = std::strtoul(typeSizeXml, nullptr, 0);
}
const char* countXml = reader->Attribute("Count");
if (countXml != nullptr)
{
isArray = true;
if (!std::string(countXml).empty())
{
count = std::strtoul(countXml, nullptr, 0);
}
}
}
int ZSymbol::GetRawDataSize()
{
if (isArray)
{
return count * typeSize;
}
return typeSize;
}
std::string ZSymbol::GetSourceOutputHeader(const std::string& prefix)
{
if (isArray)
{
if (count == 0)
{
return StringHelper::Sprintf("extern %s %s%s[];\n", type.c_str(), prefix.c_str(),
name.c_str());
}
return StringHelper::Sprintf("extern %s %s%s[%i];\n", type.c_str(), prefix.c_str(),
name.c_str(), count);
}
return StringHelper::Sprintf("extern %s %s%s;\n", type.c_str(), prefix.c_str(), name.c_str());
}
std::string ZSymbol::GetSourceTypeName()
{
return type;
}
ZResourceType ZSymbol::GetResourceType()
{
return ZResourceType::Symbol;
}