mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-12 09:50:50 +00:00
Set up multiversion assets with ZAPD and match gc-eu (#1967)
* Add ZAPD hack to deal with extracted/VERSION/ in include paths
* Extract assets to extracted/VERSION
* Add ZAPD flags to override virtual address / start offset / end offset
* Configure offsets for code and overlay assets
* Reorganize ZAPD configs
* Match gc-eu-mq
* Match gc-eu
* Remove old asset dirs during distclean
* Revert "Remove old asset dirs during distclean"
This reverts commit fc8027a75f
.
* make zapd addresses globals int64_t so they can store uint32_t addresses and -1
* slight cleanup extract_assets.py
* git subrepo pull --force tools/ZAPD
subrepo:
subdir: "tools/ZAPD"
merged: "0285e11f0"
upstream:
origin: "https://github.com/zeldaret/ZAPD.git"
branch: "master"
commit: "0285e11f0"
git-subrepo:
version: "0.4.6"
origin: "git@github.com:ingydotnet/git-subrepo.git"
commit: "110b9eb"
---------
Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
This commit is contained in:
parent
b2d80568b9
commit
9def6f4d0d
92 changed files with 4911 additions and 487 deletions
|
@ -21,6 +21,8 @@ enum class CsFloatType
|
|||
HexOnly,
|
||||
FloatOnly,
|
||||
HexAndFloat,
|
||||
HexAndCommentedFloatLeft,
|
||||
HexAndCommentedFloatRight,
|
||||
};
|
||||
|
||||
class Globals
|
||||
|
@ -39,6 +41,9 @@ public:
|
|||
fs::path baseRomPath, inputPath, outputPath, sourceOutputPath, cfgPath;
|
||||
TextureType texType;
|
||||
CsFloatType floatType = CsFloatType::FloatOnly;
|
||||
int64_t baseAddress = -1;
|
||||
int64_t startOffset = -1;
|
||||
int64_t endOffset = -1;
|
||||
ZGame game;
|
||||
GameConfig cfg;
|
||||
bool verboseUnaccounted = false;
|
||||
|
|
|
@ -37,11 +37,14 @@ void Arg_EnableGCCCompat(int& i, char* argv[]);
|
|||
void Arg_ForceStatic(int& i, char* argv[]);
|
||||
void Arg_ForceUnaccountedStatic(int& i, char* argv[]);
|
||||
void Arg_CsFloatMode(int& i, char* argv[]);
|
||||
void Arg_BaseAddress(int& i, char* argv[]);
|
||||
void Arg_StartOffset(int& i, char* argv[]);
|
||||
void Arg_EndOffset(int& i, char* argv[]);
|
||||
|
||||
int main(int argc, char* argv[]);
|
||||
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
|
||||
ZFileMode fileMode);
|
||||
ZFileMode fileMode);
|
||||
|
||||
void ParseArgs(int& argc, char* argv[]);
|
||||
|
||||
|
@ -115,7 +118,7 @@ int main(int argc, char* argv[])
|
|||
returnCode = HandleExtract(fileMode, exporterSet);
|
||||
else if (fileMode == ZFileMode::BuildTexture)
|
||||
BuildAssetTexture(Globals::Instance->inputPath, Globals::Instance->texType,
|
||||
Globals::Instance->outputPath);
|
||||
Globals::Instance->outputPath);
|
||||
else if (fileMode == ZFileMode::BuildBackground)
|
||||
BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath);
|
||||
else if (fileMode == ZFileMode::BuildBlob)
|
||||
|
@ -126,7 +129,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
|
||||
ZFileMode fileMode)
|
||||
ZFileMode fileMode)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError eResult = doc.LoadFile(xmlFilePath.string().c_str());
|
||||
|
@ -135,7 +138,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
|
|||
{
|
||||
// TODO: use XMLDocument::ErrorIDToName to get more specific error messages here
|
||||
HANDLE_ERROR(WarningType::InvalidXML,
|
||||
StringHelper::Sprintf("invalid XML file: '%s'", xmlFilePath.c_str()), "");
|
||||
StringHelper::Sprintf("invalid XML file: '%s'", xmlFilePath.c_str()), "");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -150,7 +153,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
|
|||
}
|
||||
|
||||
for (tinyxml2::XMLElement* child = root->FirstChildElement(); child != NULL;
|
||||
child = child->NextSiblingElement())
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
if (std::string_view(child->Name()) == "File")
|
||||
{
|
||||
|
@ -254,6 +257,9 @@ void ParseArgs(int& argc, char* argv[])
|
|||
{"-us", &Arg_ForceUnaccountedStatic},
|
||||
{"--unaccounted-static", &Arg_ForceUnaccountedStatic},
|
||||
{"--cs-float", &Arg_CsFloatMode},
|
||||
{"--base-address", &Arg_BaseAddress},
|
||||
{"--start-offset", &Arg_StartOffset},
|
||||
{"--end-offset", &Arg_EndOffset},
|
||||
};
|
||||
|
||||
for (int32_t i = 2; i < argc; i++)
|
||||
|
@ -409,17 +415,47 @@ void Arg_CsFloatMode([[maybe_unused]] int& i, [[maybe_unused]] char* argv[])
|
|||
{
|
||||
Globals::Instance->floatType = CsFloatType::HexAndFloat;
|
||||
}
|
||||
else if (std::strcmp(argv[i], "hex-commented-left") == 0)
|
||||
{
|
||||
Globals::Instance->floatType = CsFloatType::HexAndCommentedFloatLeft;
|
||||
}
|
||||
else if (std::strcmp(argv[i], "hex-commented-right") == 0)
|
||||
{
|
||||
Globals::Instance->floatType = CsFloatType::HexAndCommentedFloatRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals::Instance->floatType = CsFloatType::FloatOnly;
|
||||
HANDLE_WARNING(
|
||||
WarningType::Always, "Invalid CS Float Type",
|
||||
StringHelper::Sprintf("Invalid CS float type entered. Expected \"hex\", \"float\", or "
|
||||
"\"both\". Got %s.\n Defaulting to \"float\".",
|
||||
argv[i]));
|
||||
StringHelper::Sprintf("Invalid CS float type entered. Expected \"hex\", \"float\", "
|
||||
"\"both\", \"hex-commented-left\" or \"hex-commented-right\". "
|
||||
"Got %s.\n Defaulting to \"float\".",
|
||||
argv[i]));
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ParseU32Hex(char* str)
|
||||
{
|
||||
static_assert(sizeof(uint32_t) <= sizeof(unsigned long));
|
||||
return (uint32_t)std::stoul(str, nullptr, 16);
|
||||
}
|
||||
|
||||
void Arg_BaseAddress(int& i, char* argv[])
|
||||
{
|
||||
Globals::Instance->baseAddress = ParseU32Hex(argv[++i]);
|
||||
}
|
||||
|
||||
void Arg_StartOffset(int& i, char* argv[])
|
||||
{
|
||||
Globals::Instance->startOffset = ParseU32Hex(argv[++i]);
|
||||
}
|
||||
|
||||
void Arg_EndOffset(int& i, char* argv[])
|
||||
{
|
||||
Globals::Instance->endOffset = ParseU32Hex(argv[++i]);
|
||||
}
|
||||
|
||||
int HandleExtract(ZFileMode fileMode, ExporterSet* exporterSet)
|
||||
{
|
||||
bool procFileModeSuccess = false;
|
||||
|
@ -440,14 +476,14 @@ int HandleExtract(ZFileMode fileMode, ExporterSet* exporterSet)
|
|||
printf("Parsing external file from config: '%s'\n", externalXmlFilePath.c_str());
|
||||
|
||||
parseSuccessful = Parse(externalXmlFilePath, Globals::Instance->baseRomPath,
|
||||
extFile.outPath, ZFileMode::ExternalFile);
|
||||
extFile.outPath, ZFileMode::ExternalFile);
|
||||
|
||||
if (!parseSuccessful)
|
||||
return 1;
|
||||
}
|
||||
|
||||
parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
|
||||
Globals::Instance->outputPath, fileMode);
|
||||
Globals::Instance->outputPath, fileMode);
|
||||
if (!parseSuccessful)
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -375,33 +375,22 @@ ZResourceType ZCutscene::GetResourceType() const
|
|||
|
||||
std::string ZCutscene::GetCsEncodedFloat(float f, CsFloatType type, bool useSciNotation)
|
||||
{
|
||||
uint32_t i;
|
||||
std::memcpy(&i, &f, sizeof(i));
|
||||
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
// This default case will NEVER be reached, but GCC still gives a warning.
|
||||
case CsFloatType::HexOnly:
|
||||
{
|
||||
uint32_t i;
|
||||
std::memcpy(&i, &f, sizeof(i));
|
||||
return StringHelper::Sprintf("0x%08X", i);
|
||||
}
|
||||
case CsFloatType::FloatOnly:
|
||||
{
|
||||
if (useSciNotation)
|
||||
{
|
||||
return StringHelper::Sprintf("%.8ef", f);
|
||||
}
|
||||
return StringHelper::Sprintf("%ff", f);
|
||||
}
|
||||
return StringHelper::Sprintf(useSciNotation ? "%.8ef" : "%ff", f);
|
||||
case CsFloatType::HexAndFloat:
|
||||
{
|
||||
uint32_t i;
|
||||
std::memcpy(&i, &f, sizeof(i));
|
||||
if (useSciNotation)
|
||||
{
|
||||
return StringHelper::Sprintf("CS_FLOAT(0x%08X, %.8ef)", i, f);
|
||||
}
|
||||
return StringHelper::Sprintf("CS_FLOAT(0x%08X, %ff)", i, f);
|
||||
}
|
||||
return StringHelper::Sprintf(useSciNotation ? "CS_FLOAT(0x%08X, %.8ef)" : "CS_FLOAT(0x%08X, %ff)", i, f);
|
||||
case CsFloatType::HexAndCommentedFloatLeft:
|
||||
return StringHelper::Sprintf(useSciNotation ? "/* %.8ef */ 0x%08X" : "/* %ff */ 0x%08X", f, i);
|
||||
case CsFloatType::HexAndCommentedFloatRight:
|
||||
return StringHelper::Sprintf(useSciNotation ? "0x%08X /* %.8ef */" : "0x%08X /* %ff */", i, f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,6 +120,9 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename)
|
|||
if (reader->Attribute("BaseAddress") != nullptr)
|
||||
baseAddress = StringHelper::StrToL(reader->Attribute("BaseAddress"), 16);
|
||||
|
||||
if (mode == ZFileMode::Extract && Globals::Instance->baseAddress != -1)
|
||||
baseAddress = Globals::Instance->baseAddress;
|
||||
|
||||
if (reader->Attribute("RangeStart") != nullptr)
|
||||
rangeStart = StringHelper::StrToL(reader->Attribute("RangeStart"), 16);
|
||||
|
||||
|
@ -197,6 +200,9 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename)
|
|||
}
|
||||
|
||||
rawData = File::ReadAllBytes((basePath / name).string());
|
||||
if (mode == ZFileMode::Extract && Globals::Instance->startOffset != -1 && Globals::Instance->endOffset != -1)
|
||||
rawData = std::vector<uint8_t>(rawData.begin() + Globals::Instance->startOffset,
|
||||
rawData.begin() + Globals::Instance->endOffset);
|
||||
|
||||
if (reader->Attribute("RangeEnd") == nullptr)
|
||||
rangeEnd = rawData.size();
|
||||
|
@ -585,6 +591,12 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in
|
|||
includePath = "assets/" + StringHelper::Split(includePath, "assets/extracted/")[1];
|
||||
if (StringHelper::StartsWith(includePath, "assets/custom/"))
|
||||
includePath = "assets/" + StringHelper::Split(includePath, "assets/custom/")[1];
|
||||
// Hack for OOT: don't prefix include paths with extracted/VERSION/
|
||||
if (StringHelper::StartsWith(includePath, "extracted/")) {
|
||||
std::vector<std::string> parts = StringHelper::Split(includePath, "/");
|
||||
parts.erase(parts.begin(), parts.begin() + 2);
|
||||
includePath = StringHelper::Join(parts, "/");
|
||||
}
|
||||
|
||||
Declaration* decl = GetDeclaration(address);
|
||||
if (decl == nullptr)
|
||||
|
@ -621,6 +633,12 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in
|
|||
includePath = "assets/" + StringHelper::Split(includePath, "assets/extracted/")[1];
|
||||
if (StringHelper::StartsWith(includePath, "assets/custom/"))
|
||||
includePath = "assets/" + StringHelper::Split(includePath, "assets/custom/")[1];
|
||||
// Hack for OOT: don't prefix include paths with extracted/VERSION/
|
||||
if (StringHelper::StartsWith(includePath, "extracted/")) {
|
||||
std::vector<std::string> parts = StringHelper::Split(includePath, "/");
|
||||
parts.erase(parts.begin(), parts.begin() + 2);
|
||||
includePath = StringHelper::Join(parts, "/");
|
||||
}
|
||||
|
||||
Declaration* decl = GetDeclaration(address);
|
||||
if (decl == nullptr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue