mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-10 08:50:23 +00:00
ZAPD update: Gotta go fast! (#877)
* copy over the xml * Rename anims * A bunch of renames * minor extract_assets fixes * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "820678b4e" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "820678b4e" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Change rgb5a1 to rgba16 * eye and eyebrows * some dlists * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "6be9af65d" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "6be9af65d" git-subrepo: version: "0.4.3" origin: "???" commit: "???"
This commit is contained in:
parent
d1a5ea5110
commit
5c147e5e03
226 changed files with 2350 additions and 1492 deletions
|
@ -31,7 +31,6 @@ ZFile::ZFile()
|
|||
{
|
||||
resources = std::vector<ZResource*>();
|
||||
basePath = "";
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
declarations = std::map<uint32_t, Declaration*>();
|
||||
defines = "";
|
||||
baseAddress = 0;
|
||||
|
@ -39,15 +38,13 @@ ZFile::ZFile()
|
|||
rangeEnd = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
ZFile::ZFile(const fs::path& nOutPath, std::string nName) : ZFile()
|
||||
ZFile::ZFile(std::string nName) : ZFile()
|
||||
{
|
||||
outputPath = nOutPath;
|
||||
name = nName;
|
||||
}
|
||||
|
||||
ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath,
|
||||
const fs::path& nOutPath, std::string filename, const fs::path& nXmlFilePath,
|
||||
bool placeholderMode)
|
||||
std::string filename, const fs::path& nXmlFilePath, bool placeholderMode)
|
||||
: ZFile()
|
||||
{
|
||||
xmlFilePath = nXmlFilePath;
|
||||
|
@ -56,11 +53,6 @@ ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBase
|
|||
else
|
||||
basePath = nBasePath;
|
||||
|
||||
if (nOutPath == "")
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
else
|
||||
outputPath = nOutPath;
|
||||
|
||||
ParseXML(mode, reader, filename, placeholderMode);
|
||||
DeclareResourceSubReferences();
|
||||
}
|
||||
|
@ -85,6 +77,11 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
else
|
||||
name = filename;
|
||||
|
||||
outName = name;
|
||||
const char* outNameXml = reader->Attribute("OutName");
|
||||
if (outNameXml != nullptr)
|
||||
outName = outNameXml;
|
||||
|
||||
// TODO: This should be a variable on the ZFile, but it is a large change in order to force all
|
||||
// ZResource types to have a parent ZFile.
|
||||
const char* gameStr = reader->Attribute("Game");
|
||||
|
@ -125,8 +122,6 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
Globals::Instance->AddSegment(segment, this);
|
||||
}
|
||||
|
||||
std::string folderName = (basePath / Path::GetFileNameWithoutExtension(name)).string();
|
||||
|
||||
if (mode == ZFileMode::Extract)
|
||||
{
|
||||
if (!File::Exists((basePath / name).string()))
|
||||
|
@ -166,6 +161,15 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
}
|
||||
offsetSet.insert(offsetXml);
|
||||
}
|
||||
else if (Globals::Instance->warnNoOffset)
|
||||
{
|
||||
fprintf(stderr, "Warning No offset specified for: %s", nameXml);
|
||||
}
|
||||
else if (Globals::Instance->errorNoOffset)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Error no offset specified for %s", nameXml));
|
||||
}
|
||||
if (outNameXml != nullptr)
|
||||
{
|
||||
if (outNameSet.find(outNameXml) != outNameSet.end())
|
||||
|
@ -194,7 +198,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
ZResource* nRes = nodeMap[nodeName](this);
|
||||
|
||||
if (mode == ZFileMode::Extract)
|
||||
nRes->ExtractFromXML(child, rawData, rawDataIndex);
|
||||
nRes->ExtractFromXML(child, rawDataIndex);
|
||||
|
||||
auto resType = nRes->GetResourceType();
|
||||
if (resType == ZResourceType::Texture)
|
||||
|
@ -228,14 +232,12 @@ void ZFile::DeclareResourceSubReferences()
|
|||
}
|
||||
}
|
||||
|
||||
void ZFile::BuildSourceFile(fs::path outputDir)
|
||||
void ZFile::BuildSourceFile()
|
||||
{
|
||||
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
|
||||
if (!Directory::Exists(Globals::Instance->outputPath))
|
||||
Directory::CreateDirectory(Globals::Instance->outputPath);
|
||||
|
||||
if (!Directory::Exists(outputPath.string()))
|
||||
Directory::CreateDirectory(outputPath.string());
|
||||
|
||||
GenerateSourceFiles(outputDir);
|
||||
GenerateSourceFiles(Globals::Instance->outputPath);
|
||||
}
|
||||
|
||||
std::string ZFile::GetVarName(uint32_t address)
|
||||
|
@ -264,28 +266,26 @@ const std::vector<uint8_t>& ZFile::GetRawData() const
|
|||
return rawData;
|
||||
}
|
||||
|
||||
void ZFile::ExtractResources(fs::path outputDir)
|
||||
void ZFile::ExtractResources()
|
||||
{
|
||||
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
|
||||
if (!Directory::Exists(Globals::Instance->outputPath))
|
||||
Directory::CreateDirectory(Globals::Instance->outputPath);
|
||||
|
||||
if (!Directory::Exists(outputPath.string()))
|
||||
Directory::CreateDirectory(outputPath.string());
|
||||
|
||||
if (!Directory::Exists(Globals::Instance->sourceOutputPath.string()))
|
||||
Directory::CreateDirectory(Globals::Instance->sourceOutputPath.string());
|
||||
if (!Directory::Exists(GetSourceOutputFolderPath().string()))
|
||||
Directory::CreateDirectory(GetSourceOutputFolderPath().string());
|
||||
|
||||
for (ZResource* res : resources)
|
||||
res->PreGenSourceFiles();
|
||||
|
||||
if (Globals::Instance->genSourceFile)
|
||||
GenerateSourceFiles(outputDir);
|
||||
GenerateSourceFiles(Globals::Instance->outputPath);
|
||||
|
||||
for (ZResource* res : resources)
|
||||
{
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("Saving resource %s\n", res->GetName().c_str());
|
||||
|
||||
res->Save(outputPath);
|
||||
res->Save(Globals::Instance->outputPath);
|
||||
}
|
||||
|
||||
if (Globals::Instance->testMode)
|
||||
|
@ -553,6 +553,7 @@ uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address) const
|
|||
|
||||
bool ZFile::HasDeclaration(uint32_t address)
|
||||
{
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
return declarations.find(address) != declarations.end();
|
||||
}
|
||||
|
||||
|
@ -597,7 +598,7 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
|
|||
Globals::Instance->cfg.texturePool.end())
|
||||
{
|
||||
incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." +
|
||||
res->GetExternalExtension() + ".inc";
|
||||
res->GetExternalExtension() + ".inc";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -623,9 +624,10 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
|
|||
|
||||
sourceOutput += ProcessDeclarations();
|
||||
|
||||
std::string outPath =
|
||||
(Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c"))
|
||||
.string();
|
||||
fs::path outPath = GetSourceOutputFolderPath() / outName.stem().concat(".c");
|
||||
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("Writing C file: %s\n", outPath.c_str());
|
||||
|
||||
OutputFormatter formatter;
|
||||
formatter.Write(sourceOutput);
|
||||
|
@ -650,10 +652,12 @@ void ZFile::GenerateSourceHeaderFiles()
|
|||
|
||||
formatter.Write(ProcessExterns());
|
||||
|
||||
fs::path headerFilename =
|
||||
Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".h");
|
||||
fs::path headerFilename = GetSourceOutputFolderPath() / outName.stem().concat(".h");
|
||||
|
||||
File::WriteAllText(headerFilename.string(), formatter.GetOutput());
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("Writing H file: %s\n", headerFilename.c_str());
|
||||
|
||||
File::WriteAllText(headerFilename, formatter.GetOutput());
|
||||
}
|
||||
|
||||
void ZFile::GenerateHLIntermediette()
|
||||
|
@ -675,7 +679,7 @@ void ZFile::GenerateHLIntermediette()
|
|||
std::string ZFile::GetHeaderInclude()
|
||||
{
|
||||
return StringHelper::Sprintf("#include \"%s\"\n\n",
|
||||
(Path::GetFileNameWithoutExtension(name) + ".h").c_str());
|
||||
(outName.parent_path() / outName.stem().concat(".h")).c_str());
|
||||
}
|
||||
|
||||
void ZFile::GeneratePlaceholderDeclarations()
|
||||
|
@ -706,6 +710,11 @@ ZTexture* ZFile::GetTextureResource(uint32_t offset) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
fs::path ZFile::GetSourceOutputFolderPath() const
|
||||
{
|
||||
return Globals::Instance->sourceOutputPath / outName.parent_path();
|
||||
}
|
||||
|
||||
std::map<std::string, ZResourceFactoryFunc*>* ZFile::GetNodeMap()
|
||||
{
|
||||
static std::map<std::string, ZResourceFactoryFunc*> nodeMap;
|
||||
|
@ -909,8 +918,22 @@ std::string ZFile::ProcessDeclarations()
|
|||
nonZeroUnaccounted = true;
|
||||
}
|
||||
|
||||
if ((i % 16 == 15) && (i != (diff - 1)))
|
||||
src += "\n ";
|
||||
if (Globals::Instance->verboseUnaccounted)
|
||||
{
|
||||
if ((i % 4 == 3))
|
||||
{
|
||||
src += StringHelper::Sprintf(" // 0x%06X", unaccountedAddress + i - 3);
|
||||
if (i != (diff - 1))
|
||||
{
|
||||
src += "\n\t";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((i % 16 == 15) && (i != (diff - 1)))
|
||||
src += "\n ";
|
||||
}
|
||||
}
|
||||
|
||||
if (declarations.find(unaccountedAddress) == declarations.end())
|
||||
|
@ -920,8 +943,14 @@ std::string ZFile::ProcessDeclarations()
|
|||
std::string unaccountedPrefix = "unaccounted";
|
||||
|
||||
if (diff < 16 && !nonZeroUnaccounted)
|
||||
{
|
||||
unaccountedPrefix = "possiblePadding";
|
||||
|
||||
// Strip unnecessary padding at the end of the file.
|
||||
if (unaccountedAddress + diff >= rawData.size())
|
||||
break;
|
||||
}
|
||||
|
||||
Declaration* decl = AddDeclarationArray(
|
||||
unaccountedAddress, DeclarationAlignment::None, diff, "static u8",
|
||||
StringHelper::Sprintf("%s_%06X", unaccountedPrefix.c_str(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue