summaryrefslogtreecommitdiff
path: root/ZAPD/Main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ZAPD/Main.cpp')
-rw-r--r--ZAPD/Main.cpp108
1 files changed, 56 insertions, 52 deletions
diff --git a/ZAPD/Main.cpp b/ZAPD/Main.cpp
index 16e5960..51af8a6 100644
--- a/ZAPD/Main.cpp
+++ b/ZAPD/Main.cpp
@@ -43,9 +43,15 @@ void ErrorHandler(int sig)
size_t size = backtrace(array, nMaxFrames);
char** symbols = backtrace_symbols(array, nMaxFrames);
- // To prevent unused parameter warning
- (void)sig;
+ fprintf(stderr, "\nZAPD crashed. (Signal: %i)\n", sig);
+ fprintf(stderr, "\n\t\tYou've met with a terrible fate, haven't you?\n\n");
+ /**
+ * Other possible options:
+ * - SEA BEARS FOAM. SLEEP BEARS DREAMS. \n BOTH END IN THE SAME WAY: CRASSSH!
+ */
+
+ fprintf(stderr, "Traceback:\n");
for (size_t i = 1; i < size; i++)
{
Dl_info info;
@@ -71,7 +77,8 @@ void ErrorHandler(int sig)
fprintf(stderr, "%-3zd %s\n", i, functionName.c_str());
}
- // backtrace_symbols_fd(array, size, STDERR_FILENO);
+ fprintf(stderr, "\n");
+
free(symbols);
exit(1);
}
@@ -160,6 +167,11 @@ int main(int argc, char* argv[])
Globals::Instance->testMode = string(argv[i + 1]) == "1";
i++;
}
+ else if (arg == "-crc" ||
+ arg == "--output-crc") // Outputs a CRC file for each extracted texture.
+ {
+ Globals::Instance->outputCrc = true;
+ }
else if (arg == "-ulzdl") // Use Legacy ZDisplay List
{
Globals::Instance->useLegacyZDList = string(argv[i + 1]) == "1";
@@ -200,7 +212,8 @@ int main(int argc, char* argv[])
signal(SIGSEGV, ErrorHandler);
signal(SIGABRT, ErrorHandler);
#else
- printf("Warning: Tried to set error handler, but this build lacks support for one.\n");
+ fprintf(stderr,
+ "Warning: Tried to set error handler, but this build lacks support for one.\n");
#endif
}
else if (arg == "-v") // Verbose
@@ -216,55 +229,47 @@ int main(int argc, char* argv[])
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash);
- try
+ if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
{
- if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
- {
- bool parseSuccessful =
- Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
- Globals::Instance->outputPath, fileMode);
+ bool parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
+ Globals::Instance->outputPath, fileMode);
- if (!parseSuccessful)
- return 1;
- }
- else if (fileMode == ZFileMode::BuildTexture)
- {
- TextureType texType = Globals::Instance->texType;
-
- BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildBackground)
- {
- BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildBlob)
- {
- BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildModelIntermediette)
- {
- BuildAssetModelIntermediette(Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildAnimationIntermediette)
- {
- BuildAssetAnimationIntermediette(Globals::Instance->inputPath,
- Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildOverlay)
- {
- ZOverlay* overlay =
- ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath.string()),
- Path::GetDirectoryName(Globals::Instance->cfgPath.string()));
-
- if (overlay)
- File::WriteAllText(Globals::Instance->outputPath.string(),
- overlay->GetSourceOutputCode(""));
- }
+ if (!parseSuccessful)
+ return 1;
+ }
+ else if (fileMode == ZFileMode::BuildTexture)
+ {
+ TextureType texType = Globals::Instance->texType;
+ BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildBackground)
+ {
+ BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildBlob)
+ {
+ BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildModelIntermediette)
+ {
+ BuildAssetModelIntermediette(Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildAnimationIntermediette)
+ {
+ BuildAssetAnimationIntermediette(Globals::Instance->inputPath,
+ Globals::Instance->outputPath);
}
- catch (std::runtime_error& e)
+ else if (fileMode == ZFileMode::BuildOverlay)
{
- printf("Exception occurred: %s\n", e.what());
+ ZOverlay* overlay =
+ ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath),
+ Path::GetDirectoryName(Globals::Instance->cfgPath));
+
+ if (overlay)
+ File::WriteAllText(Globals::Instance->outputPath.string(),
+ overlay->GetSourceOutputCode(""));
}
+
delete g;
return 0;
}
@@ -327,17 +332,16 @@ void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const f
{
string name = outPath.stem().string();
- ZTexture* tex = ZTexture::FromPNG(pngFilePath.string(), texType);
+ ZTexture tex(nullptr);
+ tex.FromPNG(pngFilePath, texType);
string cfgPath = StringHelper::Split(pngFilePath.string(), ".")[0] + ".cfg";
if (File::Exists(cfgPath))
name = File::ReadAllText(cfgPath);
- string src = tex->GetSourceOutputCode(name);
+ string src = tex.GetBodySourceCode();
File::WriteAllText(outPath.string(), src);
-
- delete tex;
}
void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath)