diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-04-15 07:49:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-15 07:49:28 -0400 |
| commit | 179af7d11fd27b046edfb1bbadade865033583d7 (patch) | |
| tree | 316a55e5c0857e26184d6758a324483e029e8849 | |
| parent | 96ffc1e62720f0f43eb4885e6e7dbaf76a2f6cd2 (diff) | |
Rename "Prerender" to "Background", properly extract PolygonType1 multi format and change some structs used. (#107)
* Extract BgImage
Signed-off-by: angie <angheloalf95@gmail.com>
* improve the output a bit
Signed-off-by: angie <angheloalf95@gmail.com>
* extract backgrounds for multipoly
Signed-off-by: angie <angheloalf95@gmail.com>
* Extract the dlists of PolygonDlist
Signed-off-by: angie <angheloalf95@gmail.com>
* commands in the next line
Signed-off-by: angie <angheloalf95@gmail.com>
* Move a lot of repeated code into a class
Signed-off-by: angie <angheloalf95@gmail.com>
* Use PolygonDlist instead of MeshEntry0
Signed-off-by: angie <angheloalf95@gmail.com>
* Rename prerender to background
Signed-off-by: angie <angheloalf95@gmail.com>
* format
Signed-off-by: angie <angheloalf95@gmail.com>
* last cleanup
Signed-off-by: angie <angheloalf95@gmail.com>
* Handle jpg padding
Signed-off-by: angie <angheloalf95@gmail.com>
* Add a few checks and warnings for jpeg validity
Signed-off-by: Angie <angheloalf95@gmail.com>
* typo
Signed-off-by: Angie <angheloalf95@gmail.com>
* fix merge error
Signed-off-by: angie <angheloalf95@gmail.com>
* Fix background extraction that somehow was broken
Signed-off-by: angie <angheloalf95@gmail.com>
* re-add the trailling line feed
Signed-off-by: angie <angheloalf95@gmail.com>
* add trailing line feed again
Signed-off-by: angie <angheloalf95@gmail.com>
* fix an already fixed warning
Signed-off-by: angie <angheloalf95@gmail.com>
* fix crash when no config file is provided
* run format
39 files changed, 1135 insertions, 884 deletions
@@ -1,6 +1,15 @@ +OPTIMIZATION_ON ?= 1 + CC := g++ INC := -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2 -CFLAGS := -g -g3 -fpic -Wl,-export-dynamic -std=c++17 -O2 -rdynamic + +CFLAGS := -g -g3 -fpic -Wl,-export-dynamic -std=c++17 -rdynamic +ifeq ($(OPTIMIZATION_ON),1) + CFLAGS += -O2 +else + CFLAGS += -O0 +endif + LDFLAGS := -ldl UNAME := $(shell uname) diff --git a/ZAPD/Globals.cpp b/ZAPD/Globals.cpp index ecef685..24d4d8d 100644 --- a/ZAPD/Globals.cpp +++ b/ZAPD/Globals.cpp @@ -84,8 +84,6 @@ void Globals::ReadConfigFile(const std::string& configFilePath) if (root == nullptr) return; - cfg = new GameConfig(); - for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) { @@ -108,7 +106,7 @@ void Globals::ReadConfigFile(const std::string& configFilePath) for (std::string line : lines) { - cfg->actorList.push_back(StringHelper::Strip(line, "\r")); + cfg.actorList.push_back(StringHelper::Strip(line, "\r")); } } else if (string(child->Name()) == "ObjectList") @@ -119,7 +117,7 @@ void Globals::ReadConfigFile(const std::string& configFilePath) for (std::string line : lines) { - cfg->objectList.push_back(StringHelper::Strip(line, "\r")); + cfg.objectList.push_back(StringHelper::Strip(line, "\r")); } } else if (string(child->Name()) == "TexturePool") @@ -154,7 +152,7 @@ void Globals::ReadTexturePool(const std::string& texturePoolXmlPath) string crcStr = string(child->Attribute("CRC")); string texPath = string(child->Attribute("Path")); - cfg->texturePool[strtol(crcStr.c_str(), NULL, 16)] = texPath; + cfg.texturePool[strtol(crcStr.c_str(), NULL, 16)] = texPath; } } } @@ -183,13 +181,3 @@ bool Globals::HasSegment(int segment) { return std::find(segments.begin(), segments.end(), segment) != segments.end(); } - -GameConfig::GameConfig() -{ - segmentRefs = map<int, string>(); - segmentRefFiles = map<int, ZFile*>(); - symbolMap = std::map<uint32_t, std::string>(); - actorList = std::vector<std::string>(); - objectList = std::vector<std::string>(); - texturePool = std::map<uint32_t, std::string>(); -} diff --git a/ZAPD/Globals.h b/ZAPD/Globals.h index c7a30b5..ab52d75 100644 --- a/ZAPD/Globals.h +++ b/ZAPD/Globals.h @@ -14,7 +14,18 @@ enum VerbosityLevel VERBOSITY_DEBUG }; -class GameConfig; +class GameConfig +{ +public: + std::map<int, std::string> segmentRefs; + std::map<int, ZFile*> segmentRefFiles; + std::map<uint32_t, std::string> symbolMap; + std::vector<std::string> actorList; + std::vector<std::string> objectList; + std::map<uint32_t, std::string> texturePool; // Key = CRC, Value = Path to Shared Texture + + GameConfig() = default; +}; class Globals { @@ -32,7 +43,7 @@ public: std::string baseRomPath, inputPath, outputPath, sourceOutputPath, cfgPath; TextureType texType; ZGame game; - GameConfig* cfg; + GameConfig cfg; std::vector<ZFile*> files; std::vector<int> segments; @@ -50,21 +61,6 @@ public: bool HasSegment(int segment); }; -class GameConfig -{ -public: - std::map<int, std::string> segmentRefs; - std::map<int, ZFile*> segmentRefFiles; - std::map<uint32_t, std::string> symbolMap; - std::vector<std::string> actorList; - std::vector<std::string> objectList; - std::map<uint32_t, std::string> texturePool; // Key = CRC, Value = Path to Shared Texture - - GameConfig(); - -private: -}; - /* * Note: In being able to track references across files, there are a few major files that make use * of segments... diff --git a/ZAPD/Main.cpp b/ZAPD/Main.cpp index 963b77c..3fc4f76 100644 --- a/ZAPD/Main.cpp +++ b/ZAPD/Main.cpp @@ -7,9 +7,9 @@ #include "Overlays/ZOverlay.h" #include "Path.h" #include "ZAnimation.h" +#include "ZBackground.h" #include "ZBlob.h" #include "ZFile.h" -#include "ZPrerender.h" #include "ZTexture.h" #if !defined(_MSC_VER) && !defined(__CYGWIN__) @@ -31,7 +31,7 @@ bool Parse(const std::string& xmlFilePath, const std::string& basePath, const st void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, const std::string& outPath); -void BuildAssetPrerender(const std::string& imageFilePath, const std::string& outPath); +void BuildAssetBackground(const std::string& imageFilePath, const std::string& outPath); void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath); void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& outPath); void BuildAssetAnimationIntermediette(const std::string& animPath, const std::string& outPath); @@ -100,7 +100,7 @@ int NewMain(int argc, char* argv[]) if (buildMode == "btex") fileMode = ZFileMode::BuildTexture; else if (buildMode == "bren") - fileMode = ZFileMode::BuildPrerender; + fileMode = ZFileMode::BuildBackground; else if (buildMode == "bovl") fileMode = ZFileMode::BuildOverlay; else if (buildMode == "bsf") @@ -245,12 +245,12 @@ int NewMain(int argc, char* argv[]) BuildAssetTexture(pngFilePath, texType, outFilePath); } - else if (fileMode == ZFileMode::BuildPrerender) + else if (fileMode == ZFileMode::BuildBackground) { string imageFilePath = Globals::Instance->inputPath; string outFilePath = Globals::Instance->outputPath; - BuildAssetPrerender(imageFilePath, outFilePath); + BuildAssetBackground(imageFilePath, outFilePath); } else if (fileMode == ZFileMode::BuildBlob) { @@ -354,15 +354,12 @@ void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, delete tex; } -void BuildAssetPrerender(const std::string& imageFilePath, const std::string& outPath) +void BuildAssetBackground(const std::string& imageFilePath, const std::string& outPath) { - ZPrerender prerender = ZPrerender(nullptr); + ZBackground background(nullptr); + background.ParseBinaryFile(imageFilePath, false); - prerender.ParseBinaryFile(imageFilePath, false); - - string src = prerender.GetBodySourceCode(); - - File::WriteAllText(outPath, src); + File::WriteAllText(outPath, background.GetBodySourceCode()); } void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath) diff --git a/ZAPD/ZBackground.cpp b/ZAPD/ZBackground.cpp new file mode 100644 index 0000000..70ee1ee --- /dev/null +++ b/ZAPD/ZBackground.cpp @@ -0,0 +1,211 @@ +#include "ZBackground.h" +#include "BitConverter.h" +#include "File.h" +#include "Path.h" +#include "StringHelper.h" +#include "ZFile.h" + +REGISTER_ZFILENODE(Background, ZBackground); +// TODO: make this a configurable value when ZAPD has a configuration file. +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 + +#define JPEG_MARKER 0xFFD8FFE0 +#define MARKER_DQT 0xFFDB + +ZBackground::ZBackground(ZFile* nParent) : ZResource(nParent) +{ +} + +ZBackground::ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData, + int nRawDataIndex, ZFile* nParent) + : ZResource(nParent) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + name = GetDefaultName(prefix.c_str(), rawDataIndex); + outName = name; + + ParseRawData(); +} + +void ZBackground::ParseRawData() +{ + ZResource::ParseRawData(); + + size_t i = 0; + while (true) + { + uint8_t val = rawData.at(rawDataIndex + i); + data.push_back(val); + + if (BitConverter::ToUInt16BE(rawData, rawDataIndex + i) == 0xFFD9) + { + data.push_back(rawData.at(rawDataIndex + i + 1)); + break; + } + + i++; + } +} + +void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutName) +{ + fs::path filepath(inFolder); + if (appendOutName) + { + filepath = filepath / (outName + "." + GetExternalExtension()); + } + data = File::ReadAllBytes(filepath.string()); + + // Add padding. + data.insert(data.end(), GetRawDataSize() - data.size(), 0x00); + CheckValidJpeg(filepath); +} + +void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, + int nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); + DeclareVar("", ""); +} + +void ZBackground::CheckValidJpeg(const std::string& filepath) +{ + std::string filename = outName; + if (filepath != "") + { + filename = filepath; + } + + uint32_t jpegMarker = BitConverter::ToUInt32BE(data, 0); + if (jpegMarker != JPEG_MARKER) + { + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t Missing jpeg marker at the beginning of file: '%s'.\n" + "\t The game will skip this jpeg.\n", + filename.c_str()); + } + if (data.at(6) != 'J' || data.at(7) != 'F' || data.at(8) != 'I' || data.at(9) != 'F' || + data.at(10) != '\0') + { + std::string jfifIdentifier(data.begin() + 6, data.begin() + 6 + 5); + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t Missing 'JFIF' identifier. File: '%s'.\n" + "\t This image may be corrupted or not be a jpeg iamge.\n" + "\t The identifier found was '%s'.\n", + filename.c_str(), jfifIdentifier.c_str()); + } + uint8_t majorVersion = data.at(11); + uint8_t minorVersion = data.at(12); + if (majorVersion != 0x01 || minorVersion != 0x01) + { + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t Wrong JFIF version '%i.%02i'. File: '%s'.\n" + "\t The expected version is '1.01'. The game may not be able to decode this image " + "properly.\n", + majorVersion, minorVersion, filename.c_str()); + } + if (BitConverter::ToUInt16BE(data, 20) != MARKER_DQT) + { + // This may happen when creating the image with Exif, XMP, thumbnail, progressive, etc. + // enabled. + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t There seems to be extra data before the image data in file: '%s'.\n" + "\t The game may not be able to decode this image properly.\n", + filename.c_str()); + } + if (data.size() > GetRawDataSize()) + { + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t The image is bigger than the screen buffer. File: '%s'.\n" + "\t Image size: %zu bytes.\n" + "\t Screen buffer size: %i bytes.\n", + filename.c_str(), data.size(), GetRawDataSize()); + } +} + +int ZBackground::GetRawDataSize() +{ + // Jpgs use the whole sceen buffer, which is a u16 matrix. + return SCREEN_HEIGHT * SCREEN_WIDTH * 2; +} + +void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + + if (name == "") + auxName = GetDefaultName(prefix, rawDataIndex); + + parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(), + GetSourceTypeName(), auxName, 0, bodyStr); +} + +bool ZBackground::IsExternalResource() +{ + return true; +} + +std::string ZBackground::GetExternalExtension() +{ + return "jpg"; +} + +void ZBackground::Save(const std::string& outFolder) +{ + fs::path folder(outFolder); + fs::path filepath = folder / (outName + "." + GetExternalExtension()); + File::WriteAllBytes(filepath.string(), data); +} + +std::string ZBackground::GetBodySourceCode() +{ + std::string bodyStr = " "; + + for (size_t i = 0; i < data.size() / 8; ++i) + { + bodyStr += StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(data, i * 8)); + + if (i % 8 == 7) + bodyStr += "\n "; + } + + bodyStr += "\n"; + + return bodyStr; +} + +std::string ZBackground::GetSourceOutputCode(const std::string& prefix) +{ + std::string bodyStr = GetBodySourceCode(); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + + if (decl == nullptr) + DeclareVar(prefix, bodyStr); + else + decl->text = bodyStr; + + return ""; +} + +std::string ZBackground::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sBackground_%06X", prefix.c_str(), address); +} + +std::string ZBackground::GetSourceTypeName() +{ + return "u64"; +} + +ZResourceType ZBackground::GetResourceType() +{ + return ZResourceType::Background; +} diff --git a/ZAPD/ZPrerender.h b/ZAPD/ZBackground.h index e6314cd..775b53c 100644 --- a/ZAPD/ZPrerender.h +++ b/ZAPD/ZBackground.h @@ -4,24 +4,21 @@ #include <vector> #include "ZResource.h" -class ZPrerender : public ZResource +class ZBackground : public ZResource { protected: std::vector<uint8_t> data; public: - // ZPrerender() = default; - // ZPrerender(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, - // int nRawDataIndex, ZFile* nParent); - ZPrerender(ZFile* nParent); - ZPrerender(const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex, - ZFile* nParent); + ZBackground(ZFile* nParent); + ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex, + ZFile* nParent); void ParseRawData() override; void ParseBinaryFile(const std::string& inFolder, bool appendOutName); void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex, const std::string& nRelPath) override; - // static ZPrerender* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, - // ZFile* nParent, bool readFile); + + void CheckValidJpeg(const std::string& filepath); int GetRawDataSize() override; diff --git a/ZAPD/ZBlob.cpp b/ZAPD/ZBlob.cpp index 92ef598..66ee72f 100644 --- a/ZAPD/ZBlob.cpp +++ b/ZAPD/ZBlob.cpp @@ -74,6 +74,11 @@ string ZBlob::GetSourceOutputCode(const std::string& prefix) sourceOutput += "\n"; } + // Ensure there's always a trailing line feed to prevent dumb warnings. + // Please don't remove this line, unless you somehow made a way to prevent + // that warning when building the OoT repo. + sourceOutput += "\n"; + return sourceOutput; } diff --git a/ZAPD/ZCutscene.cpp b/ZAPD/ZCutscene.cpp index a848b4a..cdf8cfc 100644 --- a/ZAPD/ZCutscene.cpp +++ b/ZAPD/ZCutscene.cpp @@ -22,7 +22,7 @@ string ZCutscene::GetSourceOutputCode(const std::string& prefix) string output = ""; int size = 0; int32_t curPtr = 0; - + output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),\n", commands.size(), endFrame); for (int i = 0; i < commands.size(); i++) @@ -88,8 +88,8 @@ void ZCutscene::ParseRawData() && cmdID != CutsceneCommands::SetCameraFocusLink && cmdID != CutsceneCommands::SetCameraPosLink) { - numEntries = BitConverter::ToInt32BE(rawData, currentPtr); - currentPtr += 4; + numEntries = BitConverter::ToInt32BE(rawData, currentPtr); + currentPtr += 4; }*/ for (int j = 0; j < numEntries; j++) @@ -170,7 +170,7 @@ void ZCutscene::ParseRawData() break; case CutsceneCommands::Error: fprintf(stderr, "Cutscene command error %d %s %d\n", (int)cmdID, __FILE__, - __LINE__); + __LINE__); break; } @@ -370,8 +370,8 @@ string CutsceneCommand::GetCName(const std::string& prefix) string CutsceneCommand::GenerateSourceCode(const std::string& roomName, int baseAddress) { return StringHelper::Sprintf("%s %sCutsceneData%04XCmd%02X = { 0x%02X,", - GetCName(roomName).c_str(), roomName.c_str(), baseAddress, - commandIndex, commandID); + GetCName(roomName).c_str(), roomName.c_str(), baseAddress, + commandIndex, commandID); } size_t CutsceneCommand::GetCommandSize() @@ -396,7 +396,7 @@ CutsceneCameraPoint::CutsceneCameraPoint(const vector<uint8_t>& rawData, int raw } CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>& rawData, - int rawDataIndex) + int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { const uint8_t* data = rawData.data(); @@ -491,11 +491,11 @@ MusicFadeEntry::MusicFadeEntry(const vector<uint8_t>& rawData, int rawDataIndex) unknown6 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 28); unknown7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); unknown8 = (uint32_t)BitConverter::ToInt32BE(rawData, - rawDataIndex + 36); // Macro hardcodes it as zero + rawDataIndex + 36); // Macro hardcodes it as zero unknown9 = (uint32_t)BitConverter::ToInt32BE(rawData, - rawDataIndex + 40); // Macro hardcodes it as zero + rawDataIndex + 40); // Macro hardcodes it as zero unknown10 = (uint32_t)BitConverter::ToInt32BE(rawData, - rawDataIndex + 44); // Macro hardcodes it as zero + rawDataIndex + 44); // Macro hardcodes it as zero } CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& rawData, int rawDataIndex) @@ -526,11 +526,10 @@ string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, i for (size_t i = 0; i < entries.size(); i++) { result += StringHelper::Sprintf( - " CS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", - entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0, + " CS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, + entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, - entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7, entries[i]->unknown8, - entries[i]->unknown9, entries[i]->unknown10); + entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7); } return result; @@ -656,7 +655,7 @@ EnvLightingEntry::EnvLightingEntry(const vector<uint8_t>& rawData, int rawDataIn } CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& rawData, - int rawDataIndex) + int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); @@ -734,9 +733,9 @@ string CutsceneCommandUnknown9::GenerateSourceCode(const std::string& roomName, for (size_t i = 0; i < entries.size(); i++) { result += StringHelper::Sprintf("\t\tCS_CMD_09(%i, %i, %i, %i, %i, %i, %i, %i),\n", - entries[i]->base, entries[i]->startFrame, - entries[i]->endFrame, entries[i]->unk2, entries[i]->unk3, - entries[i]->unk4, entries[i]->unused0, entries[i]->unused1); + entries[i]->base, entries[i]->startFrame, + entries[i]->endFrame, entries[i]->unk2, entries[i]->unk3, + entries[i]->unk4, entries[i]->unused0, entries[i]->unused1); } return result; @@ -941,7 +940,7 @@ ActorAction::ActorAction(const vector<uint8_t>& rawData, int rawDataIndex) } CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& rawData, - int rawDataIndex) + int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); @@ -975,7 +974,7 @@ string CutsceneCommandActorAction::GenerateSourceCode(const std::string& roomNam { result += StringHelper::Sprintf( " CS_NPC_ACTION(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, " - "%i, %i),\n", + "%i, %i),\n", entries[i]->action, entries[i]->startFrame, entries[i]->endFrame, entries[i]->rotX, entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX, entries[i]->startPosY, entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY, entries[i]->endPosZ, @@ -997,7 +996,7 @@ size_t CutsceneCommandActorAction::GetCommandSize() } CutsceneCommandTerminator::CutsceneCommandTerminator(const vector<uint8_t>& rawData, - int rawDataIndex) + int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -1075,7 +1074,7 @@ SpecialActionEntry::SpecialActionEntry(const vector<uint8_t>& rawData, int rawDa } CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>& rawData, - int rawDataIndex) + int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); @@ -1090,7 +1089,7 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t> } string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomName, - int baseAddress) + int baseAddress) { string result = ""; @@ -1139,7 +1138,7 @@ size_t CutsceneCommandNop::GetCommandSize() } CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector<uint8_t>& rawData, - int rawDataIndex) + int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; diff --git a/ZAPD/ZCutsceneMM.cpp b/ZAPD/ZCutsceneMM.cpp index 40b4b1f..da6e43e 100644 --- a/ZAPD/ZCutsceneMM.cpp +++ b/ZAPD/ZCutsceneMM.cpp @@ -48,14 +48,14 @@ void ZCutsceneMM::ParseRawData() uint32_t currentPtr = rawDataIndex + 8; uint32_t lastData = 0; - // TODO currently cutscenes aren't being parsed, so just consume words until we see an end marker. + // TODO currently cutscenes aren't being parsed, so just consume words until we see an end + // marker. do { lastData = BitConverter::ToInt32BE(rawData, currentPtr); data.push_back(lastData); currentPtr += 4; - } - while (lastData != 0xFFFFFFFF); + } while (lastData != 0xFFFFFFFF); } ZResourceType ZCutsceneMM::GetResourceType() diff --git a/ZAPD/ZDisplayList.cpp b/ZAPD/ZDisplayList.cpp index 8938292..1e45380 100644 --- a/ZAPD/ZDisplayList.cpp +++ b/ZAPD/ZDisplayList.cpp @@ -2006,10 +2006,10 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) std::string texName = StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first); - if (Globals::Instance->cfg->texturePool.find(item.second->hash) != - Globals::Instance->cfg->texturePool.end()) + if (Globals::Instance->cfg.texturePool.find(item.second->hash) != + Globals::Instance->cfg.texturePool.end()) { - incStr = Globals::Instance->cfg->texturePool[item.second->hash]; + incStr = Globals::Instance->cfg.texturePool[item.second->hash]; texName = Path::GetFileNameWithoutExtension(incStr); } @@ -2109,6 +2109,11 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) curAddr += 16; } + // Ensure there's always a trailing line feed to prevent dumb warnings. + // Please don't remove this line, unless you somehow made a way to prevent + // that warning when building the OoT repo. + declaration += "\n"; + vtxDeclarations[vtxKeys[i]] = declaration; if (parent != nullptr) diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index eb2b0ea..3676908 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -8,13 +8,13 @@ #include "Path.h" #include "ZAnimation.h" #include "ZArray.h" +#include "ZBackground.h" #include "ZBlob.h" #include "ZCollision.h" #include "ZCutscene.h" #include "ZDisplayList.h" #include "ZLimb.h" #include "ZMtx.h" -#include "ZPrerender.h" #include "ZRoom/ZRoom.h" #include "ZScalar.h" #include "ZSkeleton.h" @@ -530,17 +530,17 @@ void ZFile::GenerateSourceFiles(string outputDir) ZTexture* tex = (ZTexture*)res; // POOL CHECK - if (Globals::Instance->cfg->texturePool.find(tex->hash) != - Globals::Instance->cfg->texturePool.end()) + if (Globals::Instance->cfg.texturePool.find(tex->hash) != + Globals::Instance->cfg.texturePool.end()) { - incStr = Globals::Instance->cfg->texturePool[tex->hash]; + incStr = Globals::Instance->cfg.texturePool[tex->hash]; res->SetName(Path::GetFileNameWithoutExtension(incStr)); } incStr += ".c"; } else if (res->GetResourceType() == ZResourceType::Blob || - res->GetResourceType() == ZResourceType::Prerender) + res->GetResourceType() == ZResourceType::Background) { incStr += ".c"; } diff --git a/ZAPD/ZFile.h b/ZAPD/ZFile.h index caa41a9..0bb6309 100644 --- a/ZAPD/ZFile.h +++ b/ZAPD/ZFile.h @@ -13,7 +13,7 @@ enum class ZFileMode BuildAnimationIntermediette, BuildBlob, BuildSourceFile, - BuildPrerender, + BuildBackground, Extract, Invalid }; diff --git a/ZAPD/ZPrerender.cpp b/ZAPD/ZPrerender.cpp deleted file mode 100644 index e5a1822..0000000 --- a/ZAPD/ZPrerender.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include "ZPrerender.h" -#include "BitConverter.h" -#include "File.h" -#include "Path.h" -#include "StringHelper.h" -#include "ZFile.h" - -REGISTER_ZFILENODE(Prerender, ZPrerender); - -ZPrerender::ZPrerender(ZFile* nParent) : ZResource(nParent) -{ - // ParseXML(reader); -} - -ZPrerender::ZPrerender(const std::string& prefix, const std::vector<uint8_t>& nRawData, - int nRawDataIndex, ZFile* nParent) - : ZResource(nParent) -{ - name = GetDefaultName(prefix.c_str(), rawDataIndex); - outName = name; - - ExtractFromXML(nullptr, nRawData, nRawDataIndex, ""); -} - -void ZPrerender::ParseRawData() -{ - ZResource::ParseRawData(); - - size_t i = 0; - while (true) - { - uint8_t val = rawData.at(rawDataIndex + i); - data.push_back(val); - - if (BitConverter::ToUInt16BE(rawData, rawDataIndex + i) == 0xFFD9) - { - data.push_back(rawData.at(rawDataIndex + i + 1)); - break; - } - - i++; - } -} - -void ZPrerender::ParseBinaryFile(const std::string& inFolder, bool appendOutName) -{ - fs::path filepath(inFolder); - if (appendOutName) - { - filepath = filepath / (outName + "." + GetExternalExtension()); - } - data = File::ReadAllBytes(filepath.string()); -} - -void ZPrerender::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, - int nRawDataIndex, const std::string& nRelPath) -{ - ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); - DeclareVar("", ""); -} - -// ZPrerender* ZPrerender::BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, -// ZFile* nParent, bool readFile) -//{ -// ZPrerender* back = new ZPrerender(reader, nParent); -// -// back->ParseXML(reader); -// -// if (readFile) -// back->ParseBinaryFile(inFolder, true); -// -// return back; -//} - -int ZPrerender::GetRawDataSize() -{ - return data.size(); -} - -void ZPrerender::DeclareVar(const std::string& prefix, const std::string& bodyStr) -{ - std::string auxName = name; - - if (name == "") - auxName = GetDefaultName(prefix, rawDataIndex); - - parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(), - GetSourceTypeName(), auxName, 0, bodyStr); - - /*parent->AddDeclarationIncludeArray(rawDataIndex, - StringHelper::Sprintf("%s/%s.%s.inc.c", outputDir.c_str(), - Path::GetFileNameWithoutExtension(GetOutName()).c_str(), - GetExternalExtension().c_str()), - GetRawDataSize(), GetSourceTypeName(), GetName(), 0);*/ -} - -bool ZPrerender::IsExternalResource() -{ - return true; -} - -std::string ZPrerender::GetExternalExtension() -{ - return "jpg"; -} - -void ZPrerender::Save(const std::string& outFolder) -{ - fs::path folder(outFolder); - fs::path filepath = folder / (outName + "." + GetExternalExtension()); - File::WriteAllBytes(filepath.string(), data); -} - -std::string ZPrerender::GetBodySourceCode() -{ - std::string bodyStr = " "; - - for (size_t i = 0; i < data.size(); ++i) - { - bodyStr += StringHelper::Sprintf("0x%02X, ", data.at(i)); - - if (i % 16 == 15) - bodyStr += "\n "; - } - - bodyStr += "\n"; - - return bodyStr; -} - -std::string ZPrerender::GetSourceOutputCode(const std::string& prefix) -{ - std::string bodyStr = GetBodySourceCode(); - - Declaration* decl = parent->GetDeclaration(rawDataIndex); - - if (decl == nullptr) - DeclareVar(prefix, bodyStr); - else - decl->text = bodyStr; - - return ""; -} - -std::string ZPrerender::GetDefaultName(const std::string& prefix, uint32_t address) -{ - return StringHelper::Sprintf("%sPrerender_%06X", prefix.c_str(), address); -} - -std::string ZPrerender::GetSourceTypeName() -{ - return "u8"; -} - -ZResourceType ZPrerender::GetResourceType() -{ - return ZResourceType::Prerender; -} diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h index a4a22d8..45052b6 100644 --- a/ZAPD/ZResource.h +++ b/ZAPD/ZResource.h @@ -42,7 +42,7 @@ enum class ZResourceType CollisionHeader, Symbol, Mtx, - Prerender, + Background, }; class ZResource diff --git a/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp b/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp index 9780937..71057e9 100644 --- a/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp +++ b/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp @@ -7,7 +7,8 @@ using namespace std; -SetActorCutsceneList::SetActorCutsceneList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) +SetActorCutsceneList::SetActorCutsceneList(ZRoom* nZRoom, std::vector<uint8_t> rawData, + int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { int numCutscenes = rawData[rawDataIndex + 1]; @@ -24,22 +25,21 @@ SetActorCutsceneList::SetActorCutsceneList(ZRoom* nZRoom, std::vector<uint8_t> r currentPtr += 16; } - + string declaration = ""; for (ActorCutsceneEntry* entry : cutscenes) { - declaration += - StringHelper::Sprintf(" { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", entry->priority, - entry->length, entry->unk4, entry->unk6, entry->additionalCutscene, entry->sound, - entry->unkB, entry->unkC, entry->unkE, entry->letterboxSize); - + declaration += StringHelper::Sprintf( + " { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", entry->priority, entry->length, + entry->unk4, entry->unk6, entry->additionalCutscene, entry->sound, entry->unkB, + entry->unkC, entry->unkE, entry->letterboxSize); } zRoom->parent->AddDeclarationArray( segmentOffset, DeclarationAlignment::None, cutscenes.size() * 16, "ActorCutscene", - StringHelper::Sprintf("%sActorCutsceneList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0, - declaration); + StringHelper::Sprintf("%sActorCutsceneList0x%06X", zRoom->GetName().c_str(), segmentOffset), + 0, declaration); } SetActorCutsceneList::~SetActorCutsceneList() @@ -68,8 +68,8 @@ int32_t SetActorCutsceneList::GetRawDataSize() string SetActorCutsceneList::GenerateExterns() { - return StringHelper::Sprintf("extern ActorCutscene %sActorCutsceneList0x%06X[];\n", zRoom->GetName().c_str(), - segmentOffset); + return StringHelper::Sprintf("extern ActorCutscene %sActorCutsceneList0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); } string SetActorCutsceneList::GetCommandCName() @@ -82,16 +82,14 @@ RoomCommand SetActorCutsceneList::GetRoomCommand() return RoomCommand::SetActorCutsceneList; } -ActorCutsceneEntry::ActorCutsceneEntry(std::vector<uint8_t> rawData, int rawDataIndex) : - priority(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), - length(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), - unk4(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), - unk6(BitConverter::ToInt16BE(rawData, rawDataIndex + 6)), - additionalCutscene(BitConverter::ToInt16BE(rawData, rawDataIndex + 8)), - sound(rawData[rawDataIndex + 0xA]), - unkB(rawData[rawDataIndex + 0xB]), - unkC(BitConverter::ToInt16BE(rawData, rawDataIndex + 0xC)), - unkE(rawData[rawDataIndex + 0xE]), - letterboxSize(rawData[rawDataIndex + 0xF]) +ActorCutsceneEntry::ActorCutsceneEntry(std::vector<uint8_t> rawData, int rawDataIndex) + : priority(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), + length(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + unk4(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), + unk6(BitConverter::ToInt16BE(rawData, rawDataIndex + 6)), + additionalCutscene(BitConverter::ToInt16BE(rawData, rawDataIndex + 8)), + sound(rawData[rawDataIndex + 0xA]), unkB(rawData[rawDataIndex + 0xB]), + unkC(BitConverter::ToInt16BE(rawData, rawDataIndex + 0xC)), unkE(rawData[rawDataIndex + 0xE]), + letterboxSize(rawData[rawDataIndex + 0xF]) { } diff --git a/ZAPD/ZRoom/Commands/SetActorList.cpp b/ZAPD/ZRoom/Commands/SetActorList.cpp index 745616a..5ce8586 100644 --- a/ZAPD/ZRoom/Commands/SetActorList.cpp +++ b/ZAPD/ZRoom/Commands/SetActorList.cpp @@ -55,9 +55,9 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) } sourceOutput += - StringHelper::Sprintf("%s 0x%02X, (u32)%sActorList0x%06X };", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - numActors, roomName.c_str(), segmentOffset); + StringHelper::Sprintf("\n %s 0x%02X, (u32)%sActorList0x%06X \n};", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + numActors, roomName.c_str(), segmentOffset); // zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, // DeclarationPadding::None, GetRawDataSize(), "SCmdActorList", @@ -73,20 +73,21 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) if (Globals::Instance->game == ZGame::MM_RETAIL) { declaration += StringHelper::Sprintf( - " { %s, %i, %i, %i, SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X), 0x%04X }, //0x%06X", + " { %s, %i, %i, %i, SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X), " + "SPAWN_ROT_FLAGS(%i, 0x%04X), 0x%04X }, //0x%06X", ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ, (entry->rotX >> 7) & 0b111111111, entry->rotX & 0b1111111, (entry->rotY >> 7) & 0b111111111, entry->rotY & 0b1111111, - (entry->rotZ >> 7) & 0b111111111, entry->rotZ & 0b1111111, - (uint16_t)entry->initVar, segmentOffset + (index * 16)); + (entry->rotZ >> 7) & 0b111111111, entry->rotZ & 0b1111111, (uint16_t)entry->initVar, + segmentOffset + (index * 16)); } else { - declaration += - StringHelper::Sprintf(" { %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", - ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, - entry->posZ, entry->rotX, entry->rotY, entry->rotZ, - (uint16_t)entry->initVar, segmentOffset + (index * 16)); + declaration += StringHelper::Sprintf( + " { %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", + ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ, + entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar, + segmentOffset + (index * 16)); if (index < actors.size() - 1) declaration += "\n"; @@ -103,8 +104,8 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) padding = DeclarationPadding::None; zRoom->parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::None, padding, actors.size() * 16, - "ActorEntry", StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset), + segmentOffset, DeclarationAlignment::None, padding, actors.size() * 16, "ActorEntry", + StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset), GetActorListArraySize(), declaration); return sourceOutput; @@ -141,7 +142,7 @@ size_t SetActorList::GetActorListArraySize() string SetActorList::GenerateExterns() { return StringHelper::Sprintf("extern ActorEntry %sActorList0x%06X[%i];\n", - zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize()); + zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize()); } string SetActorList::GetCommandCName() diff --git a/ZAPD/ZRoom/Commands/SetAnimatedTextureList.cpp b/ZAPD/ZRoom/Commands/SetAnimatedTextureList.cpp index d30649b..e11ae27 100644 --- a/ZAPD/ZRoom/Commands/SetAnimatedTextureList.cpp +++ b/ZAPD/ZRoom/Commands/SetAnimatedTextureList.cpp @@ -7,14 +7,15 @@ using namespace std; -SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) +SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_t> rawData, + int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); { string declaration = ""; - + int32_t currentPtr = segmentOffset; AnimatedTexture* lastTexture = nullptr; @@ -28,16 +29,21 @@ SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_ currentPtr += 8; textures.push_back(lastTexture); - string textureName = (lastTexture->segmentOffset != 0) ? - StringHelper::Sprintf("&%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), lastTexture->segmentOffset) : "NULL"; + string textureName = + (lastTexture->segmentOffset != 0) ? + StringHelper::Sprintf("&%sAnimatedTextureParams0x%06X", + zRoom->GetName().c_str(), lastTexture->segmentOffset) : + "NULL"; - declaration += StringHelper::Sprintf(" { %i, %i, (u32)%s },", lastTexture->segment, lastTexture->type, textureName.c_str()); + declaration += StringHelper::Sprintf(" { %i, %i, (u32)%s },", lastTexture->segment, + lastTexture->type, textureName.c_str()); } while ((lastTexture->segment != 0) && (lastTexture->segment > -1)); zRoom->parent->AddDeclarationArray( segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, textures.size() * 8, "AnimatedTexture", - StringHelper::Sprintf("%sAnimatedTextureList0x%06X", zRoom->GetName().c_str(), segmentOffset), + StringHelper::Sprintf("%sAnimatedTextureList0x%06X", zRoom->GetName().c_str(), + segmentOffset), textures.size(), declaration); } @@ -63,23 +69,26 @@ SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_ zRoom->parent->AddDeclarationArray( texture->segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, texture->params.size() * 4, "ScrollingTextureParams", - StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), texture->segmentOffset), + StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), + texture->segmentOffset), texture->params.size(), declaration); break; case 2: case 3: case 4: zRoom->parent->AddDeclaration( - texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, - 16, "FlashingTextureParams", - StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), texture->segmentOffset), + texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 16, + "FlashingTextureParams", + StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), + texture->segmentOffset), texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset)); break; case 5: zRoom->parent->AddDeclaration( - texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, - 12, "CyclingTextureParams", - StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), texture->segmentOffset), + texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 12, + "CyclingTextureParams", + StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), + texture->segmentOffset), texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset)); break; case 6: @@ -90,14 +99,16 @@ SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_ SetAnimatedTextureList::~SetAnimatedTextureList() { - for (AnimatedTexture* texture : textures) + for (AnimatedTexture* texture : textures) delete texture; } string SetAnimatedTextureList::GenerateSourceCodePass1(string roomName, int baseAddress) { - return StringHelper::Sprintf("%s 0, (u32)%sAnimatedTextureList0x%06X", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf( + "%s 0, (u32)%sAnimatedTextureList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + zRoom->GetName().c_str(), segmentOffset); } int32_t SetAnimatedTextureList::GetRawDataSize() @@ -134,10 +145,9 @@ string SetAnimatedTextureList::GetSourceOutputCode(std::string prefix) return ""; } -AnimatedTexture::AnimatedTexture(std::vector<uint8_t> rawData, int rawDataIndex) : - segment(rawData[rawDataIndex]), - type(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), - segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) +AnimatedTexture::AnimatedTexture(std::vector<uint8_t> rawData, int rawDataIndex) + : segment(rawData[rawDataIndex]), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) { switch (type) { @@ -156,22 +166,20 @@ AnimatedTexture::AnimatedTexture(std::vector<uint8_t> rawData, int rawDataIndex) case 5: params.push_back(new CyclingTextureParams(rawData, segmentOffset)); break; - case 6: // Some terminator when there are no animated textures? + case 6: // Some terminator when there are no animated textures? break; } } AnimatedTexture::~AnimatedTexture() { - for (AnitmatedTextureParams* param : params) + for (AnitmatedTextureParams* param : params) delete param; } -ScrollingTexture::ScrollingTexture(std::vector<uint8_t> rawData, int rawDataIndex) : - xStep(rawData[rawDataIndex + 0]), - yStep(rawData[rawDataIndex + 1]), - width(rawData[rawDataIndex + 2]), - height(rawData[rawDataIndex + 3]) +ScrollingTexture::ScrollingTexture(std::vector<uint8_t> rawData, int rawDataIndex) + : xStep(rawData[rawDataIndex + 0]), yStep(rawData[rawDataIndex + 1]), + width(rawData[rawDataIndex + 2]), height(rawData[rawDataIndex + 3]) { } @@ -185,29 +193,24 @@ size_t ScrollingTexture::GetParamsSize() return 4; } -FlashingTexturePrimColor::FlashingTexturePrimColor(std::vector<uint8_t> rawData, int rawDataIndex) : - r(rawData[rawDataIndex + 0]), - g(rawData[rawDataIndex + 1]), - b(rawData[rawDataIndex + 2]), - a(rawData[rawDataIndex + 3]), - lodFrac(rawData[rawDataIndex + 4]) +FlashingTexturePrimColor::FlashingTexturePrimColor(std::vector<uint8_t> rawData, int rawDataIndex) + : r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]), + a(rawData[rawDataIndex + 3]), lodFrac(rawData[rawDataIndex + 4]) { } -FlashingTextureEnvColor::FlashingTextureEnvColor(std::vector<uint8_t> rawData, int rawDataIndex) : - r(rawData[rawDataIndex + 0]), - g(rawData[rawDataIndex + 1]), - b(rawData[rawDataIndex + 2]), - a(rawData[rawDataIndex + 3]) +FlashingTextureEnvColor::FlashingTextureEnvColor(std::vector<uint8_t> rawData, int rawDataIndex) + : r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]), + a(rawData[rawDataIndex + 3]) { } -FlashingTexture::FlashingTexture(std::vector<uint8_t> rawData, int rawDataIndex, int type) : - cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), - numKeyFrames(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), - primColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))), - envColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))), - keyFrameSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 12))) +FlashingTexture::FlashingTexture(std::vector<uint8_t> rawData, int rawDataIndex, int type) + : cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + numKeyFrames(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), + primColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))), + envColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))), + keyFrameSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 12))) { int length = (type == 2) ? cycleLength : numKeyFrames; @@ -217,14 +220,14 @@ FlashingTexture::FlashingTexture(std::vector<uint8_t> rawData, int rawDataIndex, primColors.push_back(FlashingTexturePrimColor(rawData, currentPtr)); currentPtr += 5; } - + currentPtr = envColorSegmentOffset; for (int i = 0; i < length; i++) { envColors.push_back(FlashingTextureEnvColor(rawData, currentPtr)); currentPtr += 4; } - + currentPtr = keyFrameSegmentOffset; for (int i = 0; i < length; i++) { @@ -242,21 +245,23 @@ std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, int baseAddress) for (FlashingTexturePrimColor& color : primColors) { - declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r, color.g, color.b, color.a, color.lodFrac); + declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },", + color.r, color.g, color.b, color.a, color.lodFrac); if (index < primColors.size() - 1) declaration += "\n"; - - index++; + + index++; } zRoom->parent->AddDeclarationArray( primColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, primColors.size() * 5, "FlashingTexturePrimColor", - StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(), primColorSegmentOffset), + StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(), + primColorSegmentOffset), primColors.size(), declaration); } - + if (envColorSegmentOffset != 0) { string declaration = ""; @@ -264,21 +269,23 @@ std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, int baseAddress) for (FlashingTextureEnvColor& color : envColors) { - declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r, color.g, color.b, color.a); + declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r, + color.g, color.b, color.a); if (index < envColors.size() - 1) declaration += "\n"; - - index++; + + index++; } zRoom->parent->AddDeclarationArray( envColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, envColors.size() * 4, "Color_RGBA8", - StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(), envColorSegmentOffset), + StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(), + envColorSegmentOffset), envColors.size(), declaration); } - + if (keyFrameSegmentOffset != 0) { string declaration = ""; @@ -290,21 +297,35 @@ std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, int baseAddress) if (index < keyFrames.size() - 1) declaration += "\n"; - - index++; + + index++; } - zRoom->parent->AddDeclarationArray( - keyFrameSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, - keyFrames.size() * 2, "u16", - StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", zRoom->GetName().c_str(), keyFrameSegmentOffset), - keyFrames.size(), declaration); + zRoom->parent->AddDeclarationArray(keyFrameSegmentOffset, DeclarationAlignment::Align4, + DeclarationPadding::None, keyFrames.size() * 2, "u16", + StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", + zRoom->GetName().c_str(), + keyFrameSegmentOffset), + keyFrames.size(), declaration); } - return StringHelper::Sprintf("%i, %i, (u32)%s, (u32)%s, (u32)%s", cycleLength, numKeyFrames, - (primColorSegmentOffset != 0) ? StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(), primColorSegmentOffset).c_str() : "NULL", - (envColorSegmentOffset != 0) ? StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(), envColorSegmentOffset).c_str() : "NULL", - (keyFrameSegmentOffset != 0) ? StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", zRoom->GetName().c_str(), keyFrameSegmentOffset).c_str() : "NULL"); + return StringHelper::Sprintf( + "%i, %i, (u32)%s, (u32)%s, (u32)%s", cycleLength, numKeyFrames, + (primColorSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(), + primColorSegmentOffset) + .c_str() : + "NULL", + (envColorSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(), + envColorSegmentOffset) + .c_str() : + "NULL", + (keyFrameSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", zRoom->GetName().c_str(), + keyFrameSegmentOffset) + .c_str() : + "NULL"); } size_t FlashingTexture::GetParamsSize() @@ -312,14 +333,15 @@ size_t FlashingTexture::GetParamsSize() return 16; } -CyclingTextureParams::CyclingTextureParams(std::vector<uint8_t> rawData, int rawDataIndex) : - cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), - textureSegmentOffsetsSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))), - textureIndicesSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))) +CyclingTextureParams::CyclingTextureParams(std::vector<uint8_t> rawData, int rawDataIndex) + : cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + textureSegmentOffsetsSegmentOffset( + GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))), + textureIndicesSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))) { int32_t currentPtr = textureIndicesSegmentOffset; int maxIndex = 0; - + for (int i = 0; i < cycleLength; i++) { int newIndex = rawData[currentPtr]; @@ -328,7 +350,7 @@ CyclingTextureParams::CyclingTextureParams(std::vector<uint8_t> rawData, int raw if (newIndex > maxIndex) maxIndex = newIndex; } - + currentPtr = textureSegmentOffsetsSegmentOffset; for (int i = 0; i < maxIndex + 1; i++) { @@ -346,21 +368,23 @@ std::string CyclingTextureParams::GenerateSourceCode(ZRoom* zRoom, int baseAddre for (uint32_t offset : textureSegmentOffsets) { - declaration += StringHelper::Sprintf(" %sTex_%06X,", zRoom->GetName().c_str(), offset); + declaration += + StringHelper::Sprintf(" %sTex_%06X,", zRoom->GetName().c_str(), offset); if (index < textureSegmentOffsets.size() - 1) declaration += "\n"; - - index++; + + index++; } zRoom->parent->AddDeclarationArray( - textureSegmentOffsetsSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, - textureSegmentOffsets.size() * 4, "u64*", - StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(), textureSegmentOffsetsSegmentOffset), + textureSegmentOffsetsSegmentOffset, DeclarationAlignment::Align4, + DeclarationPadding::None, textureSegmentOffsets.size() * 4, "u64*", + StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(), + textureSegmentOffsetsSegmentOffset), textureSegmentOffsets.size(), declaration); } - + if (textureIndicesSegmentOffset != 0) { string declaration = ""; @@ -372,24 +396,33 @@ std::string CyclingTextureParams::GenerateSourceCode(ZRoom* zRoom, int baseAddre if (index < textureIndices.size() - 1) declaration += "\n"; - - index++; + + index++; } zRoom->parent->AddDeclarationArray( textureIndicesSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, textureIndices.size(), "u8", - StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(), textureIndicesSegmentOffset), + StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(), + textureIndicesSegmentOffset), textureIndices.size(), declaration); } - return StringHelper::Sprintf("%i, (u32)%s, (u32)%s", cycleLength, - (textureSegmentOffsetsSegmentOffset != 0) ? StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(), textureSegmentOffsetsSegmentOffset).c_str() : "NULL", - (textureIndicesSegmentOffset != 0) ? StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(), textureIndicesSegmentOffset).c_str() : "NULL"); + return StringHelper::Sprintf( + "%i, (u32)%s, (u32)%s", cycleLength, + (textureSegmentOffsetsSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(), + textureSegmentOffsetsSegmentOffset) + .c_str() : + "NULL", + (textureIndicesSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(), + textureIndicesSegmentOffset) + .c_str() : + "NULL"); } size_t CyclingTextureParams::GetParamsSize() { return 12; } - diff --git a/ZAPD/ZRoom/Commands/SetAnimatedTextureList.h b/ZAPD/ZRoom/Commands/SetAnimatedTextureList.h index a0d2dd4..c16d0dd 100644 --- a/ZAPD/ZRoom/Commands/SetAnimatedTextureList.h +++ b/ZAPD/ZRoom/Commands/SetAnimatedTextureList.h @@ -27,7 +27,7 @@ class FlashingTexturePrimColor { public: FlashingTexturePrimColor(std::vector<uint8_t> rawData, int rawDataIndex); - + uint8_t r; uint8_t g; uint8_t b; @@ -58,7 +58,7 @@ public: uint32_t primColorSegmentOffset; uint32_t envColorSegmentOffset; uint32_t keyFrameSegmentOffset; - + std::vector<FlashingTexturePrimColor> primColors; std::vector<FlashingTextureEnvColor> envColors; std::vector<uint16_t> keyFrames; @@ -74,7 +74,7 @@ public: uint16_t cycleLength; uint32_t textureSegmentOffsetsSegmentOffset; uint32_t textureIndicesSegmentOffset; - + std::vector<uint32_t> textureSegmentOffsets; std::vector<uint8_t> textureIndices; }; diff --git a/ZAPD/ZRoom/Commands/SetCsCamera.cpp b/ZAPD/ZRoom/Commands/SetCsCamera.cpp index 762d01c..582e623 100644 --- a/ZAPD/ZRoom/Commands/SetCsCamera.cpp +++ b/ZAPD/ZRoom/Commands/SetCsCamera.cpp @@ -33,12 +33,13 @@ SetCsCamera::SetCsCamera(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDat if (numPoints > 0) { uint32_t currentPtr = cameras[0]->segmentOffset; - - for (int i = 0; i < numPoints; i++) { + + for (int i = 0; i < numPoints; i++) + { int16_t x = BitConverter::ToInt16BE(rawData, currentPtr + 0); int16_t y = BitConverter::ToInt16BE(rawData, currentPtr + 2); int16_t z = BitConverter::ToInt16BE(rawData, currentPtr + 4); - Vec3s p = { x, y, z }; + Vec3s p = {x, y, z}; points.push_back(p); currentPtr += 6; } @@ -70,8 +71,8 @@ string SetCsCamera::GenerateSourceCodePass2(string roomName, int baseAddress) sourceOutput += StringHelper::Sprintf("%s %i, (u32)&%sCsCameraList0x%06X };", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - cameras.size(), roomName.c_str(), segmentOffset); + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + cameras.size(), roomName.c_str(), segmentOffset); if (points.size() > 0) { @@ -80,7 +81,7 @@ string SetCsCamera::GenerateSourceCodePass2(string roomName, int baseAddress) for (Vec3s point : points) { declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y, - point.z, cameras[0]->segmentOffset + (index * 6)); + point.z, cameras[0]->segmentOffset + (index * 6)); if (index < points.size() - 1) declaration += "\n"; @@ -88,11 +89,12 @@ string SetCsCamera::GenerateSourceCodePass2(string roomName, int baseAddress) index++; } - zRoom->parent->AddDeclarationArray( - cameras[0]->segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, - points.size() * 6, "Vec3s", - StringHelper::Sprintf("%sCsCameraPoints0x%06X", roomName.c_str(), cameras[0]->segmentOffset), - points.size(), declaration); + zRoom->parent->AddDeclarationArray(cameras[0]->segmentOffset, DeclarationAlignment::None, + DeclarationPadding::None, points.size() * 6, "Vec3s", + StringHelper::Sprintf("%sCsCameraPoints0x%06X", + roomName.c_str(), + cameras[0]->segmentOffset), + points.size(), declaration); } { @@ -102,8 +104,9 @@ string SetCsCamera::GenerateSourceCodePass2(string roomName, int baseAddress) size_t pointsIndex = 0; for (CsCameraEntry* entry : cameras) { - declaration += StringHelper::Sprintf(" %i, %i, (u32)&%sCsCameraPoints0x%06X[%i],", entry->type, - entry->numPoints, roomName.c_str(), cameras[0]->segmentOffset, pointsIndex); + declaration += StringHelper::Sprintf(" %i, %i, (u32)&%sCsCameraPoints0x%06X[%i],", + entry->type, entry->numPoints, roomName.c_str(), + cameras[0]->segmentOffset, pointsIndex); if (index < cameras.size() - 1) declaration += "\n"; @@ -142,10 +145,9 @@ RoomCommand SetCsCamera::GetRoomCommand() return RoomCommand::SetCsCamera; } -CsCameraEntry::CsCameraEntry(std::vector<uint8_t> rawData, int rawDataIndex) : - baseOffset(rawDataIndex), - type(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), - numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), - segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) +CsCameraEntry::CsCameraEntry(std::vector<uint8_t> rawData, int rawDataIndex) + : baseOffset(rawDataIndex), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), + numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) { } diff --git a/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/ZAPD/ZRoom/Commands/SetCutscenes.cpp index b760102..e9c2240 100644 --- a/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -10,7 +10,7 @@ using namespace std; SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { - numCutscenes = rawData[rawDataIndex + 1]; + numCutscenes = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); uint32_t curPtr = segmentOffset; @@ -19,7 +19,8 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97) { ZCutscene* cutscene = new ZCutscene(nZRoom->parent); - cutscene->ExtractFromXML(nullptr, rawData, segmentOffset, + cutscene->ExtractFromXML( + nullptr, rawData, segmentOffset, ""); // TODO: Use ExtractFromFile() here when that gets implemented cutscenes.push_back(cutscene); } @@ -34,26 +35,28 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD cutsceneEntries.push_back(entry); currentPtr += 8; - declaration += StringHelper::Sprintf(" { %sCutsceneData0x%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(), - entry->segmentOffset, entry->exit, entry->entrance, entry->flag); + declaration += StringHelper::Sprintf( + " { %sCutsceneData0x%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(), + entry->segmentOffset, entry->exit, entry->entrance, entry->flag); - if (i <numCutscenes - 1) + if (i < numCutscenes - 1) declaration += "\n"; ZCutsceneMM* cutscene = new ZCutsceneMM(nZRoom->parent); - cutscene->ExtractFromXML(nullptr, rawData, entry->segmentOffset, + cutscene->ExtractFromXML( + nullptr, rawData, entry->segmentOffset, ""); // TODO: Use ExtractFromFile() here when that gets implemented cutscenes.push_back(cutscene); - //cutscenes.push_back(new ZCutsceneMM(rawData, entry->segmentOffset, 9999)); + // cutscenes.push_back(new ZCutsceneMM(rawData, entry->segmentOffset, 9999)); } zRoom->parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, - cutsceneEntries.size() * 8, "CutsceneEntry", - StringHelper::Sprintf("%sCutsceneEntryList0x%06X", zRoom->GetName().c_str(), - segmentOffset), - cutsceneEntries.size(), declaration); + segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, + cutsceneEntries.size() * 8, "CutsceneEntry", + StringHelper::Sprintf("%sCutsceneEntryList0x%06X", zRoom->GetName().c_str(), + segmentOffset), + cutsceneEntries.size(), declaration); } for (ZCutsceneBase* cutscene : cutscenes) @@ -68,13 +71,14 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD if (decl == nullptr) { DeclarationPadding padding = (Globals::Instance->game == ZGame::MM_RETAIL) ? - DeclarationPadding::None : DeclarationPadding::Pad16; + DeclarationPadding::None : + DeclarationPadding::Pad16; zRoom->parent->AddDeclarationArray( cutscene->getSegmentOffset(), DeclarationAlignment::None, padding, cutscene->GetRawDataSize(), "s32", StringHelper::Sprintf("%sCutsceneData0x%06X", zRoom->GetName().c_str(), - cutscene->getSegmentOffset()), + cutscene->getSegmentOffset()), 0, output); } else if (decl->text == "") @@ -100,10 +104,11 @@ string SetCutscenes::GenerateSourceCodePass1(string roomName, int baseAddress) Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); if (decl != nullptr) { - return StringHelper::Sprintf("%s %i, (u32)%s", pass1.c_str(), numCutscenes, decl->varName.c_str()); + return StringHelper::Sprintf("%s %i, (u32)%s", pass1.c_str(), numCutscenes, + decl->varName.c_str()); } - return StringHelper::Sprintf("%s %i, (u32)%sCutsceneData0x%06X", pass1.c_str(), - numCutscenes, zRoom->GetName().c_str(), segmentOffset); + return StringHelper::Sprintf("%s %i, (u32)%sCutsceneData0x%06X", pass1.c_str(), numCutscenes, + zRoom->GetName().c_str(), segmentOffset); } int32_t SetCutscenes::GetRawDataSize() @@ -115,8 +120,8 @@ string SetCutscenes::GenerateExterns() { if (Globals::Instance->game == ZGame::MM_RETAIL) { - return StringHelper::Sprintf("extern CutsceneEntry %sCutsceneEntryList0x%06X[];\n", zRoom->GetName().c_str(), - segmentOffset); + return StringHelper::Sprintf("extern CutsceneEntry %sCutsceneEntryList0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); } Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); @@ -125,7 +130,7 @@ string SetCutscenes::GenerateExterns() return StringHelper::Sprintf("extern s32 %s[];\n", decl->varName.c_str()); } return StringHelper::Sprintf("extern s32 %sCutsceneData0x%06X[];\n", zRoom->GetName().c_str(), - segmentOffset); + segmentOffset); } string SetCutscenes::GetCommandCName() @@ -143,10 +148,9 @@ string SetCutscenes::GetSourceOutputCode(std::string prefix) return ""; } -CutsceneEntry::CutsceneEntry(std::vector<uint8_t> rawData, int rawDataIndex) : - segmentOffset(BitConverter::ToInt32BE(rawData, rawDataIndex + 0) & 0x00FFFFFF), - exit(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), - entrance(rawData[rawDataIndex + 6]), - flag(rawData[rawDataIndex + 7]) +CutsceneEntry::CutsceneEntry(std::vector<uint8_t> rawData, int rawDataIndex) + : segmentOffset(BitConverter::ToInt32BE(rawData, rawDataIndex + 0) & 0x00FFFFFF), + exit(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), entrance(rawData[rawDataIndex + 6]), + flag(rawData[rawDataIndex + 7]) { } diff --git a/ZAPD/ZRoom/Commands/SetCutscenes.h b/ZAPD/ZRoom/Commands/SetCutscenes.h index cf21d14..e59f8dd 100644 --- a/ZAPD/ZRoom/Commands/SetCutscenes.h +++ b/ZAPD/ZRoom/Commands/SetCutscenes.h @@ -30,9 +30,9 @@ public: private: std::vector<ZCutsceneBase*> cutscenes; - std::vector<CutsceneEntry*> cutsceneEntries; // (MM Only) + std::vector<CutsceneEntry*> cutsceneEntries; // (MM Only) uint32_t segmentOffset; - uint8_t numCutscenes; // (MM Only) + uint8_t numCutscenes; // (MM Only) std::vector<uint8_t> _rawData; int _rawDataIndex; };
\ No newline at end of file diff --git a/ZAPD/ZRoom/Commands/SetLightList.cpp b/ZAPD/ZRoom/Commands/SetLightList.cpp index 2ccc465..0f81f0c 100644 --- a/ZAPD/ZRoom/Commands/SetLightList.cpp +++ b/ZAPD/ZRoom/Commands/SetLightList.cpp @@ -31,7 +31,8 @@ SetLightList::SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD currentPtr += 14; declarations += StringHelper::Sprintf( - " { 0x%02X, { %i, %i, %i, { 0x%02X, 0x%02X, 0x%02X }, 0x%02X, 0x%04X } },", type, x, y, z, r, g, b, drawGlow, radius); + " { 0x%02X, { %i, %i, %i, { 0x%02X, 0x%02X, 0x%02X }, 0x%02X, 0x%04X } },", type, x, + y, z, r, g, b, drawGlow, radius); if (i < this->numLights - 1) declarations += "\n"; diff --git a/ZAPD/ZRoom/Commands/SetMesh.cpp b/ZAPD/ZRoom/Commands/SetMesh.cpp index cd5f6b9..1a8c99e 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.cpp +++ b/ZAPD/ZRoom/Commands/SetMesh.cpp @@ -5,7 +5,7 @@ #include "../../StringHelper.h" #include "../../ZFile.h" #include "../ZRoom.h" -#include "ZPrerender.h" +#include "ZBackground.h" using namespace std; @@ -17,19 +17,17 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); string declaration = ""; - int8_t meshHeaderType = rawData[segmentOffset + 0]; + meshHeaderType = rawData[segmentOffset + 0]; if (meshHeaderType == 0) { - MeshHeader0* meshHeader0 = new MeshHeader0(); - meshHeader0->headerType = 0; - meshHeader0->entries = vector<MeshEntry0*>(); - - meshHeader0->dListStart = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 4)); - meshHeader0->dListEnd = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 8)); + uint32_t dListStart = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 4), + zRoom->parent->baseAddress); + uint32_t dListEnd = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 8), + zRoom->parent->baseAddress); int8_t numEntries = rawData[segmentOffset + 1]; - uint32_t currentPtr = meshHeader0->dListStart; + uint32_t currentPtr = dListStart; // Hack for Syotes for (int i = 0; i < abs(segAddressOffset); i++) @@ -38,220 +36,80 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, segmentOffset--; } - for (int i = 0; i < numEntries; i++) + if (numEntries > 0) { - MeshEntry0* entry = new MeshEntry0(); - entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 0)); - entry->translucentDListAddr = - GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 4)); + std::string polyGfxBody = ""; + std::string polyGfxType = ""; + int polyGfxSize = 0; - if (entry->opaqueDListAddr != 0) + for (int i = 0; i < numEntries; i++) { - entry->opaqueDList = new ZDisplayList( - rawData, entry->opaqueDListAddr, - ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr, - Globals::Instance->game == ZGame::OOT_SW97 ? - DListType::F3DEX : - DListType::F3DZEX), - zRoom->parent); - entry->opaqueDList->scene = zRoom->scene; - GenDListDeclarations(rawData, entry->opaqueDList); - } + PolygonDlist polyGfxList(zRoom->GetName(), rawData, currentPtr, zRoom->parent, + zRoom); + if (polyGfxList.opaDList != nullptr) + { + GenDListDeclarations(rawData, polyGfxList.opaDList); + } + if (polyGfxList.xluDList != nullptr) + { + GenDListDeclarations(rawData, polyGfxList.xluDList); + } + polyGfxBody += polyGfxList.GetBodySourceCode(true); + polyGfxType = polyGfxList.GetSourceTypeName(); + polyGfxSize = polyGfxList.GetRawDataSize(); - if (entry->translucentDListAddr != 0) - { - entry->translucentDList = new ZDisplayList( - rawData, entry->translucentDListAddr, - ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr, - Globals::Instance->game == ZGame::OOT_SW97 ? - DListType::F3DEX : - DListType::F3DZEX), - zRoom->parent); - entry->translucentDList->scene = zRoom->scene; - GenDListDeclarations(rawData, entry->translucentDList); + currentPtr += polyGfxList.GetRawDataSize(); } - meshHeader0->entries.push_back(entry); - - currentPtr += 8; + zRoom->parent->AddDeclarationArray( + dListStart, DeclarationAlignment::Align4, numEntries * polyGfxSize, polyGfxType, + StringHelper::Sprintf("%s%s0x%06X", zRoom->GetName().c_str(), polyGfxType.c_str(), + dListStart), + numEntries, polyGfxBody); } - declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", meshHeader0->entries.size()); + declaration = "\n "; + declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", numEntries); + declaration += "\n "; - if (meshHeader0->dListStart != 0) - declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ", - zRoom->GetName().c_str(), meshHeader0->dListStart); - else - declaration += "0, "; + std::string entriesStr = "NULL"; - if (meshHeader0->dListEnd != 0) - declaration += StringHelper::Sprintf( - "(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)", - zRoom->GetName().c_str(), meshHeader0->dListStart, zRoom->GetName().c_str(), - meshHeader0->dListStart); + if (dListStart != 0) + { + entriesStr = zRoom->parent->GetDeclaration(dListStart)->varName; + } + declaration += StringHelper::Sprintf("%s, ", entriesStr.c_str()); + declaration += "\n "; + + if (dListEnd != 0) + declaration += StringHelper::Sprintf("%s + ARRAY_COUNT(%s), ", entriesStr.c_str(), + entriesStr.c_str()); else - declaration += "0"; + declaration += "NULL, "; + declaration += "\n"; zRoom->parent->AddDeclaration( segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0", StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration); - declaration = ""; - - for (size_t i = 0; i < meshHeader0->entries.size(); i++) - { - if (meshHeader0->entries[i]->opaqueDListAddr != 0) - declaration += - StringHelper::Sprintf(" { (u32)%sDL_%06X, ", zRoom->GetName().c_str(), - meshHeader0->entries[i]->opaqueDListAddr); - else - declaration += " { 0, "; - - if (meshHeader0->entries[i]->translucentDListAddr != 0) - declaration += - StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(), - meshHeader0->entries[i]->translucentDListAddr); - else - declaration += "0 },\n"; - } - - zRoom->parent->AddDeclarationArray( - meshHeader0->dListStart, DeclarationAlignment::None, DeclarationPadding::None, - (meshHeader0->entries.size() * 8) + 0, "MeshEntry0", - StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(), - meshHeader0->dListStart), - meshHeader0->entries.size(), declaration); - - zRoom->parent->AddDeclaration(meshHeader0->dListStart + (meshHeader0->entries.size() * 8) + - 0, - DeclarationAlignment::None, DeclarationPadding::Pad16, 4, - "static s32", "terminatorMaybe", " 0x01000000 "); - - meshHeader = meshHeader0; + zRoom->parent->AddDeclaration(dListStart + (numEntries * 8), DeclarationAlignment::None, + DeclarationPadding::Pad16, 4, "static s32", "terminatorMaybe", + "0x01000000"); } else if (meshHeaderType == 1) { - MeshHeader1Base* meshHeader1 = nullptr; - - uint8_t fmt = rawData[segmentOffset + 1]; - - if (fmt == 1) // Single Format + PolygonType1 polygon1(zRoom->GetName().c_str(), rawData, segmentOffset, zRoom->parent, + zRoom); + if (polygon1.polyGfxList.opaDList != nullptr) { - MeshHeader1Single* headerSingle = new MeshHeader1Single(); - std::string headerSingleStr = StringHelper::Sprintf( - "%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset); - - headerSingle->headerType = 1; - headerSingle->format = fmt; - headerSingle->entryRecord = - BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF; - - headerSingle->imagePtr = - BitConverter::ToInt32BE(rawData, segmentOffset + 8); // &0x00FFFFFF; - headerSingle->unknown = BitConverter::ToInt32BE(rawData, segmentOffset + 12); - headerSingle->unknown2 = BitConverter::ToInt32BE(rawData, segmentOffset + 16); - headerSingle->bgWidth = BitConverter::ToInt16BE(rawData, segmentOffset + 20); - headerSingle->bgHeight = BitConverter::ToInt16BE(rawData, segmentOffset + 22); - headerSingle->imageFormat = rawData[segmentOffset + 24]; - headerSingle->imageSize = rawData[segmentOffset + 25]; - headerSingle->imagePal = BitConverter::ToInt16BE(rawData, segmentOffset + 26); - headerSingle->imageFlip = BitConverter::ToInt16BE(rawData, segmentOffset + 28); - - declaration = "\n"; - std::string entryRecordStr = "NULL"; - if (headerSingle->entryRecord != 0) - { - uint32_t entryRecordAddress = - Seg2Filespace(headerSingle->entryRecord, zRoom->parent->baseAddress); - Declaration* decl = zRoom->parent->GetDeclaration(entryRecordAddress); - - if (decl == nullptr) - { - PolygonDlist* gfxList = new PolygonDlist(headerSingleStr, rawData, - entryRecordAddress, zRoom->parent); - gfxList->DeclareAndGenerateOutputCode(); - entryRecordStr = "&" + gfxList->GetName(); - } - else - { - entryRecordStr = "&" + decl->varName; - } - } - declaration += - StringHelper::Sprintf(" { { 1 }, 1, %s }, \n", entryRecordStr.c_str()); - - std::string imagePtrStr = "NULL"; - if (headerSingle->imagePtr != 0) - { - uint32_t imagePtrAddress = - Seg2Filespace(headerSingle->imagePtr, zRoom->parent->baseAddress); - Declaration* decl = zRoom->parent->GetDeclaration(imagePtrAddress); - - if (decl == nullptr) - { - ZPrerender* prerender = - new ZPrerender(headerSingleStr, rawData, imagePtrAddress, zRoom->parent); - prerender->DeclareVar(headerSingleStr, ""); - zRoom->parent->resources.push_back(prerender); - imagePtrStr = prerender->GetName(); - } - else - { - imagePtrStr = decl->varName; - } - } - declaration += StringHelper::Sprintf(" %s, \n", imagePtrStr.c_str()); - - declaration += StringHelper::Sprintf(" 0x%06X, 0x%06X, \n", headerSingle->unknown, - headerSingle->unknown2); - declaration += StringHelper::Sprintf(" %i, %i, %i, %i, %i, %i\n", - headerSingle->bgWidth, headerSingle->bgHeight, - headerSingle->imageFormat, headerSingle->imageSize, - headerSingle->imagePal, headerSingle->imageFlip); - - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, - DeclarationPadding::Pad16, 0x1E, "MeshHeader1Single", - headerSingleStr, declaration); - - meshHeader1 = headerSingle; + GenDListDeclarations(rawData, polygon1.polyGfxList.opaDList); } - else if (fmt == 2) // Multi-Format + if (polygon1.polyGfxList.xluDList != nullptr) { - MeshHeader1Multi* headerMulti = new MeshHeader1Multi(); - - headerMulti->headerType = 1; - headerMulti->format = fmt; - headerMulti->entryRecord = - BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF; - - headerMulti->bgCnt = rawData[segmentOffset + 8]; - headerMulti->bgRecordPtr = BitConverter::ToInt32BE(rawData, segmentOffset + 12); - - declaration += StringHelper::Sprintf("{ { 1 }, 2, 0x%06X }, 0x%06X, 0x%06X", - headerMulti->entryRecord, headerMulti->bgCnt, - headerMulti->bgRecordPtr); - - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, - DeclarationPadding::Pad16, 16, "MeshHeader1Multi", - StringHelper::Sprintf("%sMeshHeader0x%06X", - zRoom->GetName().c_str(), - segmentOffset), - declaration); - - meshHeader1 = headerMulti; + GenDListDeclarations(rawData, polygon1.polyGfxList.xluDList); } - else // UH OH - { - if (Globals::Instance->verbosity >= VERBOSITY_INFO) - fprintf(stderr, "WARNING: MeshHeader FMT %i not implemented!\n", fmt); - } - - meshHeader1->headerType = 1; - meshHeader1->format = fmt; - meshHeader1->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4) & 0x00FFFFFF; - - meshHeader = meshHeader1; + polygon1.DeclareAndGenerateOutputCode(); } else if (meshHeaderType == 2) { @@ -273,9 +131,9 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, entry->playerXMin = BitConverter::ToInt16BE(rawData, currentPtr + 4); entry->playerZMin = BitConverter::ToInt16BE(rawData, currentPtr + 6); - entry->opaqueDListAddr = BitConverter::ToInt32BE(rawData, currentPtr + 8) & 0x00FFFFFF; + entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 8)); entry->translucentDListAddr = - BitConverter::ToInt32BE(rawData, currentPtr + 12) & 0x00FFFFFF; + GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 12)); if (entry->opaqueDListAddr != 0) { @@ -323,6 +181,7 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, meshHeader2->dListStart); else declaration += "0"; + declaration += "\n"; zRoom->parent->AddDeclaration( segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2", @@ -393,8 +252,7 @@ void SetMesh::GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* d if (Globals::Instance->game == ZGame::MM_RETAIL) alignment = DeclarationAlignment::None; zRoom->parent->AddDeclarationArray( - vtxEntry.first, alignment, - dList->vertices[vtxEntry.first].size() * 16, "static Vtx", + vtxEntry.first, alignment, dList->vertices[vtxEntry.first].size() * 16, "static Vtx", StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first), dList->vertices[vtxEntry.first].size(), vtxEntry.second); } @@ -431,83 +289,18 @@ string SetMesh::GenerateSourceCodePass1(string roomName, int baseAddress) { string sourceOutput = ""; - sourceOutput += - StringHelper::Sprintf("%s %i, (u32)&%sMeshHeader0x%06X", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - data, zRoom->GetName().c_str(), segmentOffset); + Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); - /*if (meshHeader->headerType == 0) - { - MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader; + sourceOutput += StringHelper::Sprintf( + "%s %i, &%s", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), data, + decl->varName.c_str()); - } - else - { - sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; - } -*/ return sourceOutput; } string SetMesh::GenerateExterns() { - string sourceOutput = ""; - - if (meshHeader->headerType == 0) - { - MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader; - - sourceOutput += StringHelper::Sprintf("extern MeshHeader0 %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - sourceOutput += StringHelper::Sprintf("extern MeshEntry0 %sMeshDListEntry0x%06X[%i];\n", - zRoom->GetName().c_str(), meshHeader0->dListStart, - meshHeader0->entries.size()); - - for (MeshEntry0* entry : meshHeader0->entries) - { - if (entry->opaqueDList != nullptr) - sourceOutput += GenDListExterns(entry->opaqueDList); - - if (entry->translucentDList != nullptr) - sourceOutput += GenDListExterns(entry->translucentDList); - } - } - else if (meshHeader->headerType == 1) - { - MeshHeader1Base* meshHeader1 = (MeshHeader1Base*)meshHeader; - - if (meshHeader1->format == 1) - sourceOutput += StringHelper::Sprintf("extern MeshHeader1Single %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - else if (meshHeader1->format == 2) - sourceOutput += StringHelper::Sprintf("extern MeshHeader1Multi %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - } - else if (meshHeader->headerType == 2) - { - MeshHeader2* meshHeader2 = (MeshHeader2*)meshHeader; - - sourceOutput += StringHelper::Sprintf("extern MeshHeader2 %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - sourceOutput += StringHelper::Sprintf("extern MeshEntry2 %sMeshDListEntry0x%06X[%i];\n", - zRoom->GetName().c_str(), meshHeader2->dListStart, - meshHeader2->entries.size()); - - for (MeshEntry2* entry : meshHeader2->entries) - { - if (entry->opaqueDList != nullptr) - sourceOutput += GenDListExterns(entry->opaqueDList); - - if (entry->translucentDList != nullptr) - sourceOutput += GenDListExterns(entry->translucentDList); - } - } - else - { - // sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; - } - - return sourceOutput; + return ""; } int32_t SetMesh::GetRawDataSize() @@ -526,21 +319,19 @@ RoomCommand SetMesh::GetRoomCommand() } PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData, - int nRawDataIndex, ZFile* nParent) + int nRawDataIndex, ZFile* nParent, ZRoom* nRoom) { rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; parent = nParent; + room = nRoom; name = GetDefaultName(prefix.c_str(), rawDataIndex); ParseRawData(); - // TODO: ZAPD refuses to extract this DList for some reason. - // (not even a crash/error, it just simply doesn't do it). - // For now, it will just export the address. - // opaDList = MakeDlist(opa, prefix); - // xluDList = MakeDlist(xlu, prefix); + opaDList = MakeDlist(opa, prefix); + xluDList = MakeDlist(xlu, prefix); } void PolygonDlist::ParseRawData() @@ -565,9 +356,9 @@ ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix) string dListStr = StringHelper::Sprintf("%sPolygonDlist_%06X", prefix.c_str(), dlistAddress); dlist->SetName(dListStr); - dlist->GetSourceOutputCode(prefix + "PolygonDlist"); + dlist->scene = room->scene; + dlist->GetSourceOutputCode(prefix); - // parent->resources.push_back(dlist); return dlist; } @@ -587,11 +378,19 @@ void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& body GetSourceTypeName(), auxName, bodyStr); } -std::string PolygonDlist::GetBodySourceCode() +std::string PolygonDlist::GetBodySourceCode(bool arrayElement) { - std::string bodyStr = "\n"; + std::string bodyStr = ""; std::string opaStr = "NULL"; std::string xluStr = "NULL"; + if (arrayElement) + { + bodyStr += " { \n "; + } + else + { + bodyStr += "\n"; + } if (opa != 0) { @@ -619,14 +418,24 @@ std::string PolygonDlist::GetBodySourceCode() } bodyStr += StringHelper::Sprintf(" %s, \n", opaStr.c_str()); + if (arrayElement) + { + bodyStr += " "; + } + bodyStr += StringHelper::Sprintf(" %s, \n", xluStr.c_str()); + if (arrayElement) + { + bodyStr += " },"; + } + return bodyStr; } void PolygonDlist::DeclareAndGenerateOutputCode() { - std::string bodyStr = GetBodySourceCode(); + std::string bodyStr = GetBodySourceCode(false); Declaration* decl = parent->GetDeclaration(rawDataIndex); if (decl == nullptr) @@ -653,3 +462,342 @@ std::string PolygonDlist::GetName() { return name; } + +BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData, + int nRawDataIndex, ZFile* nParent) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + isSubStruct = nIsSubStruct; + + name = GetDefaultName(prefix.c_str(), rawDataIndex); + + ParseRawData(); + sourceBackground = MakeBackground(source, prefix); +} + +void BgImage::ParseRawData() +{ + size_t pad = 0x00; + if (!isSubStruct) + { + pad = 0x04; + + unk_00 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); + id = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x02); + } + source = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x00); + unk_0C = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x04); + tlut = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x08); + width = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x0C); + height = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x0E); + fmt = BitConverter::ToUInt8BE(rawData, rawDataIndex + pad + 0x10); + siz = BitConverter::ToUInt8BE(rawData, rawDataIndex + pad + 0x11); + mode0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x12); + tlutCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x14); +} + +ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix) +{ + if (ptr == 0) + { + return nullptr; + } + + uint32_t backAddress = Seg2Filespace(ptr, parent->baseAddress); + + ZBackground* background = new ZBackground(prefix, rawData, backAddress, parent); + background->DeclareVar(prefix, ""); + parent->resources.push_back(background); + + return background; +} + +int BgImage::GetRawDataSize() +{ + return 0x1C; +} + +std::string BgImage::GetBodySourceCode(bool arrayElement) +{ + std::string bodyStr = ""; + if (arrayElement) + { + bodyStr += " { \n "; + } + + if (!isSubStruct) + { + bodyStr += StringHelper::Sprintf("0x%04X, ", unk_00); + bodyStr += StringHelper::Sprintf("%i, ", id); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + } + + std::string backgroundName = "NULL"; + if (source != 0) + { + uint32_t address = Seg2Filespace(source, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(address); + + if (decl == nullptr) + { + backgroundName += StringHelper::Sprintf("0x%08X, ", source); + } + else + { + backgroundName = decl->varName; + } + } + bodyStr += StringHelper::Sprintf("%s, ", backgroundName.c_str()); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("0x%08X, ", unk_0C); + bodyStr += StringHelper::Sprintf("0x%08X, ", tlut); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("%i, ", width); + bodyStr += StringHelper::Sprintf("%i, ", height); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("%i, ", fmt); + bodyStr += StringHelper::Sprintf("%i, ", siz); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("0x%04X, ", mode0); + bodyStr += StringHelper::Sprintf("0x%04X, ", tlutCount); + if (arrayElement) + { + bodyStr += " \n }, "; + } + + return bodyStr; +} + +std::string BgImage::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sBgImage_%06X", prefix.c_str(), address); +} + +std::string BgImage::GetSourceTypeName() +{ + return "BgImage"; +} + +std::string BgImage::GetName() +{ + return name; +} + +PolygonType1::PolygonType1(const std::string& prefix, const std::vector<uint8_t>& nRawData, + int nRawDataIndex, ZFile* nParent, ZRoom* nRoom) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + + name = GetDefaultName(prefix.c_str(), rawDataIndex); + + ParseRawData(); + + if (dlist != 0) + { + polyGfxList = + PolygonDlist(prefix, rawData, Seg2Filespace(dlist, parent->baseAddress), parent, nRoom); + } + + uint32_t listAddress; + std::string bgImageArrayBody = ""; + switch (format) + { + case 1: + single = BgImage(true, prefix, nRawData, nRawDataIndex + 0x08, parent); + break; + + case 2: + if (list != 0) + { + listAddress = Seg2Filespace(list, parent->baseAddress); + for (size_t i = 0; i < count; ++i) + { + BgImage bg(false, prefix, rawData, listAddress + i * BgImage::GetRawDataSize(), + parent); + multiList.push_back(bg); + bgImageArrayBody += bg.GetBodySourceCode(true); + if (i + 1 < count) + { + bgImageArrayBody += "\n"; + } + } + + Declaration* decl = parent->GetDeclaration(listAddress); + if (decl == nullptr) + { + parent->AddDeclarationArray( + listAddress, DeclarationAlignment::Align4, count * BgImage::GetRawDataSize(), + BgImage::GetSourceTypeName(), multiList.at(0).GetName().c_str(), count, + bgImageArrayBody); + } + } + break; + + default: + throw std::runtime_error(StringHelper::Sprintf( + "Error in PolygonType1::PolygonType1\n\t Unknown format: %i\n", format)); + break; + } +} + +void PolygonType1::ParseRawData() +{ + type = BitConverter::ToUInt8BE(rawData, rawDataIndex); + format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01); + dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04); + + if (format == 2) + { + count = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); + list = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C); + } +} + +int PolygonType1::GetRawDataSize() +{ + switch (format) + { + case 1: + return 0x20; + + case 2: + return 0x10; + } + return 0x20; +} + +void PolygonType1::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + if (name == "") + { + auxName = GetDefaultName(prefix, rawDataIndex); + } + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(), + GetSourceTypeName(), auxName, bodyStr); +} + +std::string PolygonType1::GetBodySourceCode() +{ + std::string bodyStr = "\n "; + + bodyStr += "{ "; + bodyStr += StringHelper::Sprintf("%i, %i, ", type, format); + + std::string dlistStr = "NULL"; + if (dlist != 0) + { + uint32_t entryRecordAddress = Seg2Filespace(dlist, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(entryRecordAddress); + + if (decl == nullptr) + { + polyGfxList.DeclareAndGenerateOutputCode(); + dlistStr = "&" + polyGfxList.GetName(); + } + else + { + dlistStr = "&" + decl->varName; + } + } + bodyStr += StringHelper::Sprintf("%s, ", dlistStr.c_str()); + bodyStr += "}, \n"; + + std::string listStr = "NULL"; + // bodyStr += " { \n"; + switch (format) + { + case 1: + bodyStr += " " + single.GetBodySourceCode(false) + "\n"; + break; + case 2: + if (list != 0) + { + uint32_t listAddress = Seg2Filespace(list, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(listAddress); + if (decl != nullptr) + { + listStr = decl->varName; + } + else + { + listStr = StringHelper::Sprintf("0x%08X", list); + } + } + bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str()); + break; + + default: + break; + } + // bodyStr += " } \n"; + + return bodyStr; +} + +void PolygonType1::DeclareAndGenerateOutputCode() +{ + std::string bodyStr = GetBodySourceCode(); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + if (decl == nullptr) + { + DeclareVar("", bodyStr); + } + else + { + decl->text = bodyStr; + } +} + +std::string PolygonType1::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sPolygonType1_%06X", prefix.c_str(), address); +} + +std::string PolygonType1::GetSourceTypeName() +{ + switch (format) + { + case 1: + return "MeshHeader1Single"; + + case 2: + return "MeshHeader1Multi"; + } + return "ERROR"; + // return "PolygonType1"; +} + +std::string PolygonType1::GetName() +{ + return name; +} diff --git a/ZAPD/ZRoom/Commands/SetMesh.h b/ZAPD/ZRoom/Commands/SetMesh.h index ad611d4..29329dc 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.h +++ b/ZAPD/ZRoom/Commands/SetMesh.h @@ -2,6 +2,7 @@ #include "../../ZDisplayList.h" #include "../ZRoomCommand.h" +#include "ZBackground.h" class MeshHeaderBase { @@ -9,9 +10,12 @@ public: int8_t headerType; // 0x00 }; -class MeshEntry0 +class MeshEntry2 { public: + int16_t playerXMax, playerZMax; + int16_t playerXMin, playerZMin; + int32_t opaqueDListAddr; int32_t translucentDListAddr; @@ -19,93 +23,103 @@ public: ZDisplayList* translucentDList; }; -class MeshHeader0 : public MeshHeaderBase +class MeshHeader2 : public MeshHeaderBase { public: - std::vector<MeshEntry0*> entries; + std::vector<MeshEntry2*> entries; uint32_t dListStart; uint32_t dListEnd; }; -class MeshHeader1Base : public MeshHeaderBase +class PolygonDlist { -public: - int8_t format; // 0x01 - uint32_t entryRecord; // 0x04 -}; +protected: + segptr_t opa = 0; // Gfx* + segptr_t xlu = 0; // Gfx* + + std::vector<uint8_t> rawData; + int rawDataIndex; + ZFile* parent; + ZRoom* room; + std::string name; + + void ParseRawData(); + ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix); -class MeshHeader1Single : public MeshHeader1Base -{ public: - uint32_t imagePtr; // 0x08 + PolygonDlist() = default; + PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex, + ZFile* nParent, ZRoom* nRoom); - uint32_t unknown; // 0x0C - uint32_t unknown2; // 0x10 + int GetRawDataSize(); - uint16_t bgWidth; // 0x14 - uint16_t bgHeight; // 0x16 + void DeclareVar(const std::string& prefix, const std::string& bodyStr); - uint8_t imageFormat; // 0x18 - uint8_t imageSize; // 0x19 - uint16_t imagePal; // 0x1A - uint16_t imageFlip; // 0x1C -}; + std::string GetBodySourceCode(bool arrayElement); + void DeclareAndGenerateOutputCode(); -class MeshHeader1Multi : public MeshHeader1Base -{ -public: - uint8_t bgCnt; // 0x08 - uint32_t bgRecordPtr; // 0x0C + static std::string GetDefaultName(const std::string& prefix, uint32_t address); + std::string GetSourceTypeName(); + std::string GetName(); + + ZDisplayList* opaDList = nullptr; // Gfx* + ZDisplayList* xluDList = nullptr; // Gfx* }; -class BackgroundRecord +class BgImage { -public: - uint16_t unknown; // 0x00 - int8_t bgID; // 0x02 - - uint32_t imagePtr; // 0x04 - uint32_t unknown2; // 0x08 - uint32_t unknown3; // 0x0C +protected: + uint16_t unk_00; + uint8_t id; + segptr_t source; + uint32_t unk_0C; + uint32_t tlut; + uint16_t width; + uint16_t height; + uint8_t fmt; + uint8_t siz; + uint16_t mode0; + uint16_t tlutCount; + + ZBackground* sourceBackground; - uint16_t bgWidth; // 0x10 - uint16_t bgHeight; // 0x12 + std::vector<uint8_t> rawData; + int rawDataIndex; + ZFile* parent; + std::string name; + bool isSubStruct; - uint8_t imageFmt; // 0x14 - uint8_t imageSize; // 0x15 - uint16_t imagePal; // 0x16 - uint16_t imageFlip; // 0x18 -}; + void ParseRawData(); + ZBackground* MakeBackground(segptr_t ptr, const std::string& prefix); -class MeshEntry2 -{ public: - int16_t playerXMax, playerZMax; - int16_t playerXMin, playerZMin; + BgImage() = default; + BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData, + int nRawDataIndex, ZFile* nParent); - int32_t opaqueDListAddr; - int32_t translucentDListAddr; + static int GetRawDataSize(); - ZDisplayList* opaqueDList; - ZDisplayList* translucentDList; -}; + std::string GetBodySourceCode(bool arrayElement); -class MeshHeader2 : public MeshHeaderBase -{ -public: - std::vector<MeshEntry2*> entries; - uint32_t dListStart; - uint32_t dListEnd; + static std::string GetDefaultName(const std::string& prefix, uint32_t address); + static std::string GetSourceTypeName(); + std::string GetName(); }; -class PolygonDlist +class PolygonType1 { protected: - segptr_t opa; // Gfx* - segptr_t xlu; // Gfx* + uint8_t type; + uint8_t format; + segptr_t dlist; - ZDisplayList* opaDList; // Gfx* - ZDisplayList* xluDList; // Gfx* + // single + BgImage single; + + // multi + uint8_t count; + segptr_t list; // BgImage* + std::vector<BgImage> multiList; std::vector<uint8_t> rawData; int rawDataIndex; @@ -113,11 +127,10 @@ protected: std::string name; void ParseRawData(); - ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix); public: - PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex, - ZFile* nParent); + PolygonType1(const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex, + ZFile* nParent, ZRoom* nRoom); int GetRawDataSize(); @@ -129,6 +142,8 @@ public: static std::string GetDefaultName(const std::string& prefix, uint32_t address); std::string GetSourceTypeName(); std::string GetName(); + + PolygonDlist polyGfxList; }; class SetMesh : public ZRoomCommand @@ -146,10 +161,11 @@ public: virtual int32_t GetRawDataSize(); private: - MeshHeaderBase* meshHeader; + MeshHeaderBase* meshHeader = nullptr; uint32_t segmentOffset; uint8_t data; + uint8_t meshHeaderType; void GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* dList); std::string GenDListExterns(ZDisplayList* dList); -};
\ No newline at end of file +}; diff --git a/ZAPD/ZRoom/Commands/SetMinimapChests.cpp b/ZAPD/ZRoom/Commands/SetMinimapChests.cpp index 8749296..4fd28db 100644 --- a/ZAPD/ZRoom/Commands/SetMinimapChests.cpp +++ b/ZAPD/ZRoom/Commands/SetMinimapChests.cpp @@ -40,10 +40,9 @@ string SetMinimapChests::GenerateSourceCodePass2(string roomName, int baseAddres string sourceOutput = ""; sourceOutput += - StringHelper::Sprintf( - "%s 0x%02X, (u32)%sMinimapChests0x%06X };", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), chests.size(), - roomName.c_str(), segmentOffset); + StringHelper::Sprintf("%s 0x%02X, (u32)%sMinimapChests0x%06X };", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + chests.size(), roomName.c_str(), segmentOffset); { string declaration = ""; @@ -51,8 +50,9 @@ string SetMinimapChests::GenerateSourceCodePass2(string roomName, int baseAddres size_t index = 0; for (MinimapChest* chest : chests) { - declaration += - StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },", chest->unk0, chest->unk2, chest->unk4, chest->unk6, chest->unk8); + declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },", + chest->unk0, chest->unk2, chest->unk4, chest->unk6, + chest->unk8); if (index < chests.size() - 1) declaration += "\n"; @@ -61,8 +61,8 @@ string SetMinimapChests::GenerateSourceCodePass2(string roomName, int baseAddres } zRoom->parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, - chests.size() * 10, "MinimapChest", + segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, chests.size() * 10, + "MinimapChest", StringHelper::Sprintf("%sMinimapChests0x%06X", roomName.c_str(), segmentOffset), chests.size(), declaration); } @@ -72,8 +72,8 @@ string SetMinimapChests::GenerateSourceCodePass2(string roomName, int baseAddres string SetMinimapChests::GenerateExterns() { - return StringHelper::Sprintf("extern MinimapChest %sMinimapChests0x%06X[%i];\n", zRoom->GetName().c_str(), - segmentOffset, chests.size()); + return StringHelper::Sprintf("extern MinimapChest %sMinimapChests0x%06X[%i];\n", + zRoom->GetName().c_str(), segmentOffset, chests.size()); } string SetMinimapChests::GetCommandCName() @@ -91,11 +91,11 @@ int32_t SetMinimapChests::GetRawDataSize() return ZRoomCommand::GetRawDataSize() + (chests.size() * 10); } -MinimapChest::MinimapChest(std::vector<uint8_t> rawData, int rawDataIndex) : - unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), - unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), - unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)), - unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)), - unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8)) +MinimapChest::MinimapChest(std::vector<uint8_t> rawData, int rawDataIndex) + : unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), + unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)), + unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)), + unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8)) { }
\ No newline at end of file diff --git a/ZAPD/ZRoom/Commands/SetMinimapList.cpp b/ZAPD/ZRoom/Commands/SetMinimapList.cpp index f4c8372..02ec641 100644 --- a/ZAPD/ZRoom/Commands/SetMinimapList.cpp +++ b/ZAPD/ZRoom/Commands/SetMinimapList.cpp @@ -47,16 +47,17 @@ string SetMinimapList::GenerateSourceCodePass2(string roomName, int baseAddress) sourceOutput += StringHelper::Sprintf("%s 0, (u32)&%sMinimapList0x%06X };", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - roomName.c_str(), segmentOffset, unk4); + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + roomName.c_str(), segmentOffset, unk4); { string declaration = StringHelper::Sprintf("(u32)%sMinimapEntryList0x%06X, 0x%08X", - roomName.c_str(), listSegmentOffset, unk4); + roomName.c_str(), listSegmentOffset, unk4); zRoom->parent->AddDeclaration( segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 8, "MinimapList", - StringHelper::Sprintf("%sMinimapList0x%06X", roomName.c_str(), segmentOffset), declaration); + StringHelper::Sprintf("%sMinimapList0x%06X", roomName.c_str(), segmentOffset), + declaration); } { @@ -65,8 +66,9 @@ string SetMinimapList::GenerateSourceCodePass2(string roomName, int baseAddress) size_t index = 0; for (MinimapEntry* entry : minimaps) { - declaration += - StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },", entry->unk0, entry->unk2, entry->unk4, entry->unk6, entry->unk8); + declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },", + entry->unk0, entry->unk2, entry->unk4, entry->unk6, + entry->unk8); if (index < minimaps.size() - 1) declaration += "\n"; @@ -86,8 +88,8 @@ string SetMinimapList::GenerateSourceCodePass2(string roomName, int baseAddress) string SetMinimapList::GenerateExterns() { - return StringHelper::Sprintf("extern MinimapList %sMinimapList0x%06X;\n", zRoom->GetName().c_str(), - listSegmentOffset); + return StringHelper::Sprintf("extern MinimapList %sMinimapList0x%06X;\n", + zRoom->GetName().c_str(), listSegmentOffset); } string SetMinimapList::GetCommandCName() @@ -105,11 +107,11 @@ int32_t SetMinimapList::GetRawDataSize() return ZRoomCommand::GetRawDataSize() + (minimaps.size() * 10); } -MinimapEntry::MinimapEntry(std::vector<uint8_t> rawData, int rawDataIndex) : - unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), - unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), - unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)), - unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)), - unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8)) +MinimapEntry::MinimapEntry(std::vector<uint8_t> rawData, int rawDataIndex) + : unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), + unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)), + unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)), + unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8)) { }
\ No newline at end of file diff --git a/ZAPD/ZRoom/Commands/SetObjectList.cpp b/ZAPD/ZRoom/Commands/SetObjectList.cpp index 6a88953..6d0164a 100644 --- a/ZAPD/ZRoom/Commands/SetObjectList.cpp +++ b/ZAPD/ZRoom/Commands/SetObjectList.cpp @@ -47,8 +47,7 @@ string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress) for (size_t i = 0; i < objects.size(); i++) { uint16_t objectIndex = objects[i]; - declaration += StringHelper::Sprintf( - " %s,", Globals::Instance->cfg->objectList[objectIndex].c_str()); + declaration += StringHelper::Sprintf(" %s,", ZNames::GetObjectName(objectIndex).c_str()); if (i < objects.size() - 1) declaration += "\n"; diff --git a/ZAPD/ZRoom/Commands/SetPathways.cpp b/ZAPD/ZRoom/Commands/SetPathways.cpp index a58b5b0..7e3d49c 100644 --- a/ZAPD/ZRoom/Commands/SetPathways.cpp +++ b/ZAPD/ZRoom/Commands/SetPathways.cpp @@ -1,13 +1,14 @@ #include "SetPathways.h" #include "../../BitConverter.h" +#include "../../Globals.h" #include "../../StringHelper.h" #include "../../ZFile.h" -#include "../../Globals.h" #include "../ZRoom.h" using namespace std; -SetPathways::SetPathways(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, bool isFromHeader) +SetPathways::SetPathways(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, + bool isFromHeader) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { _rawData = rawData; @@ -35,7 +36,9 @@ string SetPathways::GetSourceOutputCode(std::string prefix) string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress) { - int numPaths = (Globals::Instance->game != ZGame::MM_RETAIL) ? 1 : zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8; + int numPaths = (Globals::Instance->game != ZGame::MM_RETAIL) ? + 1 : + zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8; pathwayList = new PathwayList(zRoom, _rawData, segmentOffset, numPaths); @@ -48,11 +51,11 @@ string SetPathways::GenerateSourceCodePass2(string roomName, int baseAddress) sourceOutput += StringHelper::Sprintf("%s 0, (u32)%sPathway0x%06X };", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - roomName.c_str(), segmentOffset); + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + roomName.c_str(), segmentOffset); if (pathwayList != nullptr) - pathwayList->GetSourceOutputCode(roomName); + pathwayList->GetSourceOutputCode(roomName); return sourceOutput; } @@ -61,7 +64,7 @@ int32_t SetPathways::GetRawDataSize() { int32_t size = 0; if (pathwayList != nullptr) - size += pathwayList->GetRawDataSize(); + size += pathwayList->GetRawDataSize(); return ZRoomCommand::GetRawDataSize() + size; } @@ -69,7 +72,7 @@ int32_t SetPathways::GetRawDataSize() string SetPathways::GenerateExterns() { if (pathwayList != nullptr) - return pathwayList->GenerateExterns(); + return pathwayList->GenerateExterns(); return std::string(); } @@ -84,11 +87,10 @@ RoomCommand SetPathways::GetRoomCommand() return RoomCommand::SetPathways; } -PathwayEntry::PathwayEntry(std::vector<uint8_t> rawData, int rawDataIndex) : - numPoints(rawData[rawDataIndex + 0]), - unk1(rawData[rawDataIndex + 1]), - unk2(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), - listSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) +PathwayEntry::PathwayEntry(std::vector<uint8_t> rawData, int rawDataIndex) + : numPoints(rawData[rawDataIndex + 0]), unk1(rawData[rawDataIndex + 1]), + unk2(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + listSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) { uint32_t currentPtr = listSegmentOffset; uint8_t* data = rawData.data(); @@ -104,7 +106,7 @@ PathwayEntry::PathwayEntry(std::vector<uint8_t> rawData, int rawDataIndex) : currentPtr += 6; } - + if (numPoints == 0) // Hack for SharpOcarina { for (int i = 0; i < 3; i++) @@ -149,11 +151,13 @@ void PathwayList::GetSourceOutputCode(std::string prefix) for (PathwayEntry* entry : pathways) { if (Globals::Instance->game == ZGame::MM_RETAIL) - declaration += StringHelper::Sprintf(" { %i, %i, %i, (u32)%sPathwayList0x%06X },", entry->numPoints, - entry->unk1, entry->unk2, prefix.c_str(), entry->listSegmentOffset); + declaration += StringHelper::Sprintf(" { %i, %i, %i, (u32)%sPathwayList0x%06X },", + entry->numPoints, entry->unk1, entry->unk2, + prefix.c_str(), entry->listSegmentOffset); else - declaration += StringHelper::Sprintf(" { %i, (u32)%sPathwayList0x%06X },", entry->numPoints, - prefix.c_str(), entry->listSegmentOffset); + declaration += + StringHelper::Sprintf(" { %i, (u32)%sPathwayList0x%06X },", entry->numPoints, + prefix.c_str(), entry->listSegmentOffset); if (index < pathways.size() - 1) declaration += "\n"; @@ -176,7 +180,7 @@ void PathwayList::GetSourceOutputCode(std::string prefix) for (Vec3s& point : entry->points) { declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y, - point.z, entry->listSegmentOffset + (index * 6)); + point.z, entry->listSegmentOffset + (index * 6)); if (index < entry->points.size() - 1) declaration += "\n"; @@ -209,8 +213,8 @@ string PathwayList::GenerateExterns() string declaration = ""; for (PathwayEntry* entry : pathways) { - declaration += StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", zRoom->GetName().c_str(), - entry->listSegmentOffset); + declaration += StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", + zRoom->GetName().c_str(), entry->listSegmentOffset); } return declaration; diff --git a/ZAPD/ZRoom/Commands/SetPathways.h b/ZAPD/ZRoom/Commands/SetPathways.h index 06d0c37..8e1a00f 100644 --- a/ZAPD/ZRoom/Commands/SetPathways.h +++ b/ZAPD/ZRoom/Commands/SetPathways.h @@ -11,8 +11,8 @@ public: PathwayEntry(std::vector<uint8_t> rawData, int rawDataIndex); int numPoints; - int8_t unk1; // (MM Only) - int16_t unk2; // (MM Only) + int8_t unk1; // (MM Only) + int16_t unk2; // (MM Only) uint32_t listSegmentOffset; std::vector<Vec3s> points; }; diff --git a/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp b/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp index 3a1f3ae..317f669 100644 --- a/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp +++ b/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp @@ -1,6 +1,6 @@ #include "SetSkyboxSettings.h" -#include "../../StringHelper.h" #include "../../Globals.h" +#include "../../StringHelper.h" using namespace std; @@ -17,8 +17,8 @@ string SetSkyboxSettings::GenerateSourceCodePass1(string roomName, int baseAddre { return StringHelper::Sprintf( "%s 0x%02X, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), unk1, - skyboxNumber, cloudsType, lightingSettingsControl); + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), unk1, skyboxNumber, + cloudsType, lightingSettingsControl); } string SetSkyboxSettings::GetCommandCName() diff --git a/ZAPD/ZRoom/Commands/SetSkyboxSettings.h b/ZAPD/ZRoom/Commands/SetSkyboxSettings.h index 21ead6b..e10074f 100644 --- a/ZAPD/ZRoom/Commands/SetSkyboxSettings.h +++ b/ZAPD/ZRoom/Commands/SetSkyboxSettings.h @@ -12,7 +12,7 @@ public: virtual RoomCommand GetRoomCommand(); private: - uint8_t unk1; // (MM Only) + uint8_t unk1; // (MM Only) uint8_t skyboxNumber; uint8_t cloudsType; uint8_t lightingSettingsControl; diff --git a/ZAPD/ZRoom/Commands/SetStartPositionList.cpp b/ZAPD/ZRoom/Commands/SetStartPositionList.cpp index e1d10ae..523d583 100644 --- a/ZAPD/ZRoom/Commands/SetStartPositionList.cpp +++ b/ZAPD/ZRoom/Commands/SetStartPositionList.cpp @@ -48,10 +48,10 @@ string SetStartPositionList::GenerateSourceCodePass1(string roomName, int baseAd for (ActorSpawnEntry* entry : actors) { - declaration += StringHelper::Sprintf( - " { %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n", - Globals::Instance->cfg->actorList[entry->actorNum].c_str(), entry->posX, entry->posY, - entry->posZ, entry->rotX, entry->rotY, entry->rotZ, entry->initVar); + declaration += StringHelper::Sprintf(" { %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n", + ZNames::GetActorName(entry->actorNum).c_str(), + entry->posX, entry->posY, entry->posZ, entry->rotX, + entry->rotY, entry->rotZ, entry->initVar); } zRoom->parent->AddDeclarationArray( diff --git a/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp b/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp index 0ab167a..103d939 100644 --- a/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp +++ b/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp @@ -9,7 +9,7 @@ using namespace std; SetTransitionActorList::SetTransitionActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, - int rawDataIndex) + int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { int numActors = rawData[rawDataIndex + 1]; @@ -43,19 +43,13 @@ string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int base { string sourceOutput = StringHelper::Sprintf("%s 0x%02X, (u32)%sTransitionActorList0x%06X", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - transitionActors.size(), roomName.c_str(), segmentOffset); + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + transitionActors.size(), roomName.c_str(), segmentOffset); string declaration = ""; for (TransitionActorEntry* entry : transitionActors) { - string actorStr = ""; - - if (entry->actorNum < sizeof(Globals::Instance->cfg->actorList) / - sizeof(Globals::Instance->cfg->actorList[0])) - actorStr = Globals::Instance->cfg->actorList[entry->actorNum]; - else - actorStr = StringHelper::Sprintf("0x%04X", entry->actorNum); + string actorStr = ZNames::GetActorName(entry->actorNum); declaration += StringHelper::Sprintf( " { %i, %i, %i, %i, %s, %i, %i, %i, %i, 0x%04X }, \n", entry->frontObjectRoom, @@ -86,7 +80,7 @@ int32_t SetTransitionActorList::GetRawDataSize() string SetTransitionActorList::GenerateExterns() { return StringHelper::Sprintf("extern TransitionActorEntry %sTransitionActorList0x%06X[];\n", - zRoom->GetName().c_str(), segmentOffset); + zRoom->GetName().c_str(), segmentOffset); } string SetTransitionActorList::GetCommandCName() diff --git a/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp b/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp index 7a6a84e..5175d23 100644 --- a/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp +++ b/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp @@ -3,7 +3,8 @@ using namespace std; -SetWorldMapVisited::SetWorldMapVisited(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) +SetWorldMapVisited::SetWorldMapVisited(ZRoom* nZRoom, std::vector<uint8_t> rawData, + int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { } diff --git a/ZAPD/ZRoom/ZNames.h b/ZAPD/ZRoom/ZNames.h index 58a67a0..716b9f4 100644 --- a/ZAPD/ZRoom/ZNames.h +++ b/ZAPD/ZRoom/ZNames.h @@ -10,7 +10,9 @@ class ZNames public: static std::string GetObjectName(int id) { - return Globals::Instance->cfg->objectList[id]; + if (id >= Globals::Instance->cfg.objectList.size()) + return StringHelper::Sprintf("0x%04X", id); + return Globals::Instance->cfg.objectList.at(id); } static std::string GetActorName(int id) @@ -20,31 +22,28 @@ public: case ZGame::OOT_RETAIL: case ZGame::OOT_SW97: if (id < ZNames::GetNumActors()) - return Globals::Instance->cfg->actorList[id]; + return Globals::Instance->cfg.actorList.at(id); else return StringHelper::Sprintf("0x%04X", id); case ZGame::MM_RETAIL: - { - int flags = id & 0xF000; - id &= 0xFFF; - std::string name = ""; - if (id < ZNames::GetNumActors()) - name = Globals::Instance->cfg->actorList[id]; - else - name = StringHelper::Sprintf("0x%04X", id); + { + int flags = id & 0xF000; + id &= 0xFFF; + std::string name = ""; + if (id < ZNames::GetNumActors()) + name = Globals::Instance->cfg.actorList.at(id); + else + name = StringHelper::Sprintf("0x%04X", id); - if (flags == 0) - return name; - else - return StringHelper::Sprintf("%s | 0x%04X", name.c_str(), flags); - } + if (flags == 0) + return name; + else + return StringHelper::Sprintf("%s | 0x%04X", name.c_str(), flags); + } } return ""; } - static int GetNumActors() - { - return Globals::Instance->cfg->actorList.size(); - } + static int GetNumActors() { return Globals::Instance->cfg.actorList.size(); } }; diff --git a/ZAPD/ZRoom/ZRoom.cpp b/ZAPD/ZRoom/ZRoom.cpp index a7325f8..2eff08a 100644 --- a/ZAPD/ZRoom/ZRoom.cpp +++ b/ZAPD/ZRoom/ZRoom.cpp @@ -7,8 +7,8 @@ #include "../StringHelper.h" #include "../ZBlob.h" #include "Commands/EndMarker.h" -#include "Commands/SetActorList.h" #include "Commands/SetActorCutsceneList.h" +#include "Commands/SetActorList.h" #include "Commands/SetAlternateHeaders.h" #include "Commands/SetAnimatedTextureList.h" #include "Commands/SetCameraSettings.h" @@ -20,9 +20,9 @@ #include "Commands/SetExitList.h" #include "Commands/SetLightList.h" #include "Commands/SetLightingSettings.h" +#include "Commands/SetMesh.h" #include "Commands/SetMinimapChests.h" #include "Commands/SetMinimapList.h" -#include "Commands/SetMesh.h" #include "Commands/SetObjectList.h" #include "Commands/SetPathways.h" #include "Commands/SetRoomBehavior.h" @@ -41,7 +41,6 @@ #include "Commands/ZRoomCommandUnk.h" #include "ZCutscene.h" #include "ZFile.h" -#include "ZPrerender.h" using namespace std; using namespace tinyxml2; @@ -202,7 +201,7 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8 0, tex->GetSourceOutputCode(name)); delete tex; } - else if (string(child->Name()) == "PrerenderHint") + else if (string(child->Name()) == "BackgroundHint") { string comment = ""; @@ -212,7 +211,7 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8 string addressStr = child->Attribute("Offset"); int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); - ZPrerender* back = new ZPrerender(parent); + ZBackground* back = new ZBackground(parent); back->ExtractFromXML(reader, rawData, address, ""); parent->resources.push_back(back); } @@ -322,7 +321,7 @@ void ZRoom::ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet co case RoomCommand::SetCameraSettings: if (Globals::Instance->game == ZGame::MM_RETAIL) cmd = new SetWorldMapVisited(this, rawData, rawDataIndex); - else + else cmd = new SetCameraSettings(this, rawData, rawDataIndex); break; // 0x19 case RoomCommand::SetAnimatedTextureList: @@ -392,7 +391,7 @@ void ZRoom::ProcessCommandSets() StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()), StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID), - StringHelper::Sprintf("%s", pass1.c_str())); + StringHelper::Sprintf("\n %s\n", pass1.c_str())); decl->rightText = StringHelper::Sprintf("// 0x%04X", cmd->cmdAddress); } diff --git a/ZAPD/ZRoom/ZRoomCommand.cpp b/ZAPD/ZRoom/ZRoomCommand.cpp index 8d3baeb..370e198 100644 --- a/ZAPD/ZRoom/ZRoomCommand.cpp +++ b/ZAPD/ZRoom/ZRoomCommand.cpp @@ -1,4 +1,5 @@ #include "ZRoomCommand.h" +#include "StringHelper.h" using namespace std; @@ -11,13 +12,7 @@ ZRoomCommand::ZRoomCommand(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD string ZRoomCommand::GenerateSourceCodePass1(string roomName, int baseAddress) { - char line[2048]; - - // sprintf(line, "%s _%s_set%04X_cmd%02X = { 0x%02X,", GetCommandCName().c_str(), - // roomName.c_str(), baseAddress, cmdIndex, cmdID); - sprintf(line, " 0x%02X,", (uint8_t)cmdID); - - return string(line); + return StringHelper::Sprintf("0x%02X,", (uint8_t)cmdID); } string ZRoomCommand::GenerateSourceCodePass2(string roomName, int baseAddress) diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp index 58e0eed..10533f5 100644 --- a/ZAPD/ZTexture.cpp +++ b/ZAPD/ZTexture.cpp @@ -780,10 +780,10 @@ void ZTexture::Save(const std::string& outFolder) std::string outPath = outFolder; // POOL CHECK - if (Globals::Instance->cfg->texturePool.find(hash) != Globals::Instance->cfg->texturePool.end()) + if (Globals::Instance->cfg.texturePool.find(hash) != Globals::Instance->cfg.texturePool.end()) { - outPath = Path::GetDirectoryName(Globals::Instance->cfg->texturePool[hash]); - outName = Path::GetFileNameWithoutExtension(Globals::Instance->cfg->texturePool[hash]); + outPath = Path::GetDirectoryName(Globals::Instance->cfg.texturePool[hash]); + outName = Path::GetFileNameWithoutExtension(Globals::Instance->cfg.texturePool[hash]); } if (!Directory::Exists(outPath)) @@ -842,6 +842,11 @@ string ZTexture::GetSourceOutputCode(const std::string& prefix) sourceOutput += StringHelper::Sprintf(" // 0x%06X \n", rawDataIndex + ((i / 32) * 32)); } + // Ensure there's always a trailing line feed to prevent dumb warnings. + // Please don't remove this line, unless you somehow made a way to prevent + // that warning when building the OoT repo. + sourceOutput += "\n"; + return sourceOutput; } diff --git a/ZAPD/ZTexture.h b/ZAPD/ZTexture.h index ce0daa6..9c3ef45 100644 --- a/ZAPD/ZTexture.h +++ b/ZAPD/ZTexture.h @@ -56,9 +56,6 @@ protected: void PrepareRawDataPalette4(std::string palPath); void PrepareRawDataPalette8(std::string palPath); float GetPixelMultiplyer(); - bool IsExternalResource() override; - ZResourceType GetResourceType() override; - std::string GetSourceTypeName() override; void CalcHash() override; public: @@ -91,4 +88,8 @@ public: TextureType GetTextureType(); void Save(const std::string& outFolder) override; std::string GetExternalExtension() override; + + bool IsExternalResource() override; + std::string GetSourceTypeName() override; + ZResourceType GetResourceType() override; }; |
