summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-04-19 12:43:52 -0400
committerGitHub <noreply@github.com>2021-04-19 12:43:52 -0400
commit301e17dadb5f6e9212ebcb704eb9cff75883002e (patch)
treec1b28712d3e52f0dc5888344c28a6efc0a719a5f
parent0d79edb291f7fdeafb2aca8edc81c4f90837977d (diff)
Deprecate Hint system (#116)
* remove unnecessary param * Fix Cutscene tag * Fix a missing declaration * Add Path as a node * run format
-rw-r--r--ZAPD/ZBackground.cpp2
-rw-r--r--ZAPD/ZCollision.cpp3
-rw-r--r--ZAPD/ZCutscene.cpp100
-rw-r--r--ZAPD/ZCutscene.h66
-rw-r--r--ZAPD/ZCutsceneMM.cpp36
-rw-r--r--ZAPD/ZCutsceneMM.h5
-rw-r--r--ZAPD/ZMtx.cpp3
-rw-r--r--ZAPD/ZResource.cpp8
-rw-r--r--ZAPD/ZResource.h3
-rw-r--r--ZAPD/ZRoom/Commands/SetActorList.cpp2
-rw-r--r--ZAPD/ZRoom/Commands/SetCutscenes.cpp28
-rw-r--r--ZAPD/ZRoom/Commands/SetPathways.cpp93
-rw-r--r--ZAPD/ZRoom/Commands/SetPathways.h38
-rw-r--r--ZAPD/ZRoom/ZRoom.cpp76
-rw-r--r--ZAPD/ZRoom/ZRoomCommand.h1
15 files changed, 253 insertions, 211 deletions
diff --git a/ZAPD/ZBackground.cpp b/ZAPD/ZBackground.cpp
index c2fa87a..9743588 100644
--- a/ZAPD/ZBackground.cpp
+++ b/ZAPD/ZBackground.cpp
@@ -111,7 +111,7 @@ void ZBackground::CheckValidJpeg(const std::string& filepath)
}
if (BitConverter::ToUInt16BE(data, 20) != MARKER_DQT)
{
- // This may happen when creating the image with Exif, XMP, thumbnail, progressive, etc.
+ // This may happen when creating a custom image with Exif, XMP, thumbnail, progressive, etc.
// enabled.
fprintf(stderr,
"ZBackground::CheckValidJpeg: Warning.\n"
diff --git a/ZAPD/ZCollision.cpp b/ZAPD/ZCollision.cpp
index 05c1390..1bf1bb3 100644
--- a/ZAPD/ZCollision.cpp
+++ b/ZAPD/ZCollision.cpp
@@ -78,8 +78,7 @@ void ZCollisionHeader::ParseRawData()
}
for (uint16_t i = 0; i < highestPolyType + 1; i++)
- polygonTypes.push_back(
- BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
+ polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
if (camDataAddress != 0)
camData = new CameraDataList(parent, name, rawData, camDataSegmentOffset,
diff --git a/ZAPD/ZCutscene.cpp b/ZAPD/ZCutscene.cpp
index 7cea20c..36301ca 100644
--- a/ZAPD/ZCutscene.cpp
+++ b/ZAPD/ZCutscene.cpp
@@ -17,7 +17,7 @@ ZCutscene::~ZCutscene()
delete cmd;
}
-string ZCutscene::GetSourceOutputCode(const std::string& prefix)
+string ZCutscene::GetBodySourceCode()
{
string output = "";
int size = 0;
@@ -28,7 +28,7 @@ string ZCutscene::GetSourceOutputCode(const std::string& prefix)
for (int i = 0; i < commands.size(); i++)
{
CutsceneCommand* cmd = commands[i];
- output += " " + cmd->GenerateSourceCode(prefix, curPtr);
+ output += " " + cmd->GenerateSourceCode(curPtr);
curPtr += (uint32_t)cmd->GetCommandSize();
size += (int)cmd->GetCommandSize();
}
@@ -38,6 +38,33 @@ string ZCutscene::GetSourceOutputCode(const std::string& prefix)
return output;
}
+string ZCutscene::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 "";
+}
+
+void ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr)
+{
+ std::string auxName = name;
+
+ if (auxName == "")
+ auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
+ // auxName = GetDefaultName(prefix, getSegmentOffset());
+
+ parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4,
+ DeclarationPadding::Pad16, GetRawDataSize(), "s32", auxName, 0,
+ bodyStr);
+}
+
int ZCutscene::GetRawDataSize()
{
int size = 0;
@@ -62,6 +89,7 @@ void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<u
const int nRawDataIndex, const std::string& nRelPath)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
+ DeclareVar("", "");
}
void ZCutscene::ParseRawData()
@@ -354,16 +382,15 @@ CutsceneCommand::CutsceneCommand(const vector<uint8_t>& rawData, int rawDataInde
{
}
-string CutsceneCommand::GetCName(const std::string& prefix)
+string CutsceneCommand::GetCName()
{
return "SCmdCutsceneData";
}
-string CutsceneCommand::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommand::GenerateSourceCode(int baseAddress)
{
- return StringHelper::Sprintf("%s %sCutsceneData%04XCmd%02X = { 0x%02X,",
- GetCName(roomName).c_str(), roomName.c_str(), baseAddress,
- commandIndex, commandID);
+ return StringHelper::Sprintf("%s CutsceneData%04XCmd%02X = { 0x%02X,", GetCName().c_str(),
+ baseAddress, commandIndex, commandID);
}
size_t CutsceneCommand::GetCommandSize()
@@ -417,12 +444,12 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>&
}
// TODO
-string CutsceneCommandSetCameraPos::GetCName(const std::string& prefix)
+string CutsceneCommandSetCameraPos::GetCName()
{
return "";
}
-string CutsceneCommandSetCameraPos::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandSetCameraPos::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -504,12 +531,12 @@ CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& rawData, i
}
}
-string CutsceneCommandFadeBGM::GetCName(const std::string& prefix)
+string CutsceneCommandFadeBGM::GetCName()
{
return "CsCmdMusicFade";
}
-string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandFadeBGM::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -561,7 +588,7 @@ CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector<uint8_t>& rawData, i
}
}
-string CutsceneCommandPlayBGM::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandPlayBGM::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -579,7 +606,7 @@ string CutsceneCommandPlayBGM::GenerateSourceCode(const std::string& roomName, i
return result;
}
-string CutsceneCommandPlayBGM::GetCName(const std::string& prefix)
+string CutsceneCommandPlayBGM::GetCName()
{
return "CsCmdMusicChange";
}
@@ -603,7 +630,7 @@ CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector<uint8_t>& rawData, i
}
}
-string CutsceneCommandStopBGM::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandStopBGM::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -621,7 +648,7 @@ string CutsceneCommandStopBGM::GenerateSourceCode(const std::string& roomName, i
return result;
}
-string CutsceneCommandStopBGM::GetCName(const std::string& prefix)
+string CutsceneCommandStopBGM::GetCName()
{
return "CsCmdMusicChange";
}
@@ -661,7 +688,7 @@ CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& ra
}
}
-string CutsceneCommandEnvLighting::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandEnvLighting::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -679,7 +706,7 @@ string CutsceneCommandEnvLighting::GenerateSourceCode(const std::string& roomNam
return result;
}
-string CutsceneCommandEnvLighting::GetCName(const std::string& prefix)
+string CutsceneCommandEnvLighting::GetCName()
{
return "CsCmdEnvLighting";
}
@@ -716,7 +743,7 @@ CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector<uint8_t>& rawData,
}
}
-string CutsceneCommandUnknown9::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandUnknown9::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -733,7 +760,7 @@ string CutsceneCommandUnknown9::GenerateSourceCode(const std::string& roomName,
return result;
}
-string CutsceneCommandUnknown9::GetCName(const std::string& prefix)
+string CutsceneCommandUnknown9::GetCName()
{
return "CsCmdUnknown9";
}
@@ -773,7 +800,7 @@ CutsceneCommandUnknown::CutsceneCommandUnknown(const vector<uint8_t>& rawData, i
}
}
-string CutsceneCommandUnknown::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandUnknown::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -791,7 +818,7 @@ string CutsceneCommandUnknown::GenerateSourceCode(const std::string& roomName, i
return result;
}
-string CutsceneCommandUnknown::GetCName(const std::string& prefix)
+string CutsceneCommandUnknown::GetCName()
{
return "CsCmdUnknown1A";
}
@@ -825,12 +852,12 @@ CutsceneCommandDayTime::CutsceneCommandDayTime(const vector<uint8_t>& rawData, i
}
}
-string CutsceneCommandDayTime::GetCName(const std::string& prefix)
+string CutsceneCommandDayTime::GetCName()
{
return "CsCmdDayTime";
}
-string CutsceneCommandDayTime::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandDayTime::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -875,12 +902,12 @@ CutsceneCommandTextbox::CutsceneCommandTextbox(const vector<uint8_t>& rawData, i
}
}
-string CutsceneCommandTextbox::GetCName(const std::string& prefix)
+string CutsceneCommandTextbox::GetCName()
{
return "CsCmdTextbox";
}
-string CutsceneCommandTextbox::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandTextbox::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -946,7 +973,7 @@ CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& ra
}
}
-string CutsceneCommandActorAction::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandActorAction::GenerateSourceCode(int baseAddress)
{
string result = "";
string subCommand = "";
@@ -977,7 +1004,7 @@ string CutsceneCommandActorAction::GenerateSourceCode(const std::string& roomNam
return result;
}
-string CutsceneCommandActorAction::GetCName(const std::string& prefix)
+string CutsceneCommandActorAction::GetCName()
{
return "CsCmdBase";
}
@@ -999,12 +1026,12 @@ CutsceneCommandTerminator::CutsceneCommandTerminator(const vector<uint8_t>& rawD
unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate
}
-string CutsceneCommandTerminator::GetCName(const std::string& prefix)
+string CutsceneCommandTerminator::GetCName()
{
return "CsCmdBase";
}
-string CutsceneCommandTerminator::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandTerminator::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -1026,7 +1053,7 @@ CutsceneCommandEnd::CutsceneCommandEnd(const vector<uint8_t>& rawData, int rawDa
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
-string CutsceneCommandEnd::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandEnd::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -1035,7 +1062,7 @@ string CutsceneCommandEnd::GenerateSourceCode(const std::string& roomName, int b
return result;
}
-string CutsceneCommandEnd::GetCName(const std::string& prefix)
+string CutsceneCommandEnd::GetCName()
{
return "CsCmdBase";
}
@@ -1080,8 +1107,7 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>
}
}
-string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomName,
- int baseAddress)
+string CutsceneCommandSpecialAction::GenerateSourceCode(int baseAddress)
{
string result = "";
@@ -1101,7 +1127,7 @@ string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomN
return result;
}
-string CutsceneCommandSpecialAction::GetCName(const std::string& prefix)
+string CutsceneCommandSpecialAction::GetCName()
{
return "CsCmdBase";
}
@@ -1119,7 +1145,7 @@ CutsceneCommandNop::CutsceneCommandNop(const vector<uint8_t>& rawData, int rawDa
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
-string CutsceneCommandNop::GetCName(const std::string& prefix)
+string CutsceneCommandNop::GetCName()
{
return "CsCmdBase";
}
@@ -1140,12 +1166,12 @@ CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector<uint8_t>&
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
-string CutsceneCommandSceneTransFX::GenerateSourceCode(const std::string& roomName, int baseAddress)
+string CutsceneCommandSceneTransFX::GenerateSourceCode(int baseAddress)
{
return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame);
}
-string CutsceneCommandSceneTransFX::GetCName(const std::string& prefix)
+string CutsceneCommandSceneTransFX::GetCName()
{
return "CsCmdBase";
}
diff --git a/ZAPD/ZCutscene.h b/ZAPD/ZCutscene.h
index bc99738..0919dbb 100644
--- a/ZAPD/ZCutscene.h
+++ b/ZAPD/ZCutscene.h
@@ -63,8 +63,8 @@ public:
uint32_t commandIndex;
CutsceneCommand(const std::vector<uint8_t>& rawData, int rawDataIndex);
- virtual std::string GetCName(const std::string& prefix);
- virtual std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ virtual std::string GetCName();
+ virtual std::string GenerateSourceCode(int baseAddress);
virtual size_t GetCommandSize();
};
@@ -79,8 +79,8 @@ public:
std::vector<CutsceneCameraPoint*> entries;
CutsceneCommandSetCameraPos(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -111,8 +111,8 @@ public:
std::vector<SpecialActionEntry*> entries;
CutsceneCommandSpecialAction(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -143,8 +143,8 @@ public:
std::vector<MusicFadeEntry*> entries;
CutsceneCommandFadeBGM(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -172,8 +172,8 @@ public:
std::vector<MusicChangeEntry*> entries;
CutsceneCommandPlayBGM(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -183,8 +183,8 @@ public:
std::vector<MusicChangeEntry*> entries;
CutsceneCommandStopBGM(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -212,8 +212,8 @@ public:
std::vector<EnvLightingEntry*> entries;
CutsceneCommandEnvLighting(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -225,8 +225,8 @@ public:
uint16_t endFrame;
CutsceneCommandSceneTransFX(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -251,8 +251,8 @@ public:
std::vector<Unknown9Entry*> entries;
CutsceneCommandUnknown9(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -281,8 +281,8 @@ public:
std::vector<UnkEntry*> entries;
CutsceneCommandUnknown(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -305,8 +305,8 @@ public:
std::vector<DayTimeEntry*> entries;
CutsceneCommandDayTime(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -329,8 +329,8 @@ public:
std::vector<TextboxEntry*> entries;
CutsceneCommandTextbox(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -354,8 +354,8 @@ public:
std::vector<ActorAction*> entries;
CutsceneCommandActorAction(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -368,8 +368,8 @@ public:
uint16_t unknown;
CutsceneCommandTerminator(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -381,8 +381,8 @@ public:
uint16_t endFrame;
CutsceneCommandEnd(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
- std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
+ std::string GetCName();
+ std::string GenerateSourceCode(int baseAddress);
size_t GetCommandSize();
};
@@ -394,7 +394,7 @@ public:
uint16_t endFrame;
CutsceneCommandNop(const std::vector<uint8_t>& rawData, int rawDataIndex);
- std::string GetCName(const std::string& prefix);
+ std::string GetCName();
size_t GetCommandSize();
};
@@ -402,6 +402,8 @@ class ZCutsceneBase : public ZResource
{
public:
ZCutsceneBase(ZFile* nParent);
+ virtual std::string GetBodySourceCode() = 0;
+ virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) = 0;
virtual uint32_t getSegmentOffset() = 0;
};
@@ -411,6 +413,8 @@ public:
ZCutscene(ZFile* nParent);
~ZCutscene();
+ std::string GetBodySourceCode() override;
+ void DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
CutsceneCommands GetCommandFromID(int id);
diff --git a/ZAPD/ZCutsceneMM.cpp b/ZAPD/ZCutsceneMM.cpp
index da6e43e..6b7e389 100644
--- a/ZAPD/ZCutsceneMM.cpp
+++ b/ZAPD/ZCutsceneMM.cpp
@@ -14,7 +14,7 @@ ZCutsceneMM::~ZCutsceneMM()
delete cmd;
}
-string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
+string ZCutsceneMM::GetBodySourceCode()
{
string output = "";
size_t size = 0;
@@ -32,11 +32,45 @@ string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
return output;
}
+string ZCutsceneMM::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 "";
+}
+
+void ZCutsceneMM::DeclareVar(const std::string& prefix, const std::string& bodyStr)
+{
+ std::string auxName = name;
+
+ if (auxName == "")
+ auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
+ // auxName = GetDefaultName(prefix, getSegmentOffset());
+
+ parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4,
+ DeclarationPadding::Pad16, GetRawDataSize(), "s32", auxName, 0,
+ bodyStr);
+}
+
int ZCutsceneMM::GetRawDataSize()
{
return 8 + data.size() * 4;
}
+void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
+ const int nRawDataIndex, const std::string& nRelPath)
+{
+ ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
+ DeclareVar("", "");
+}
+
void ZCutsceneMM::ParseRawData()
{
segmentOffset = rawDataIndex;
diff --git a/ZAPD/ZCutsceneMM.h b/ZAPD/ZCutsceneMM.h
index cc98339..f5f0f79 100644
--- a/ZAPD/ZCutsceneMM.h
+++ b/ZAPD/ZCutsceneMM.h
@@ -15,6 +15,8 @@ public:
ZCutsceneMM(ZFile* nParent);
~ZCutsceneMM();
+ std::string GetBodySourceCode() override;
+ void DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
uint32_t getSegmentOffset() override { return segmentOffset; }
@@ -22,6 +24,9 @@ public:
void ParseRawData() override;
ZResourceType GetResourceType() override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
+ const int nRawDataIndex, const std::string& nRelPath) override;
+
protected:
int numCommands;
int endFrame;
diff --git a/ZAPD/ZMtx.cpp b/ZAPD/ZMtx.cpp
index 82e78ab..37b4c9b 100644
--- a/ZAPD/ZMtx.cpp
+++ b/ZAPD/ZMtx.cpp
@@ -14,7 +14,8 @@ ZMtx::ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, int
: ZResource(nParent)
{
name = GetDefaultName(prefix.c_str(), rawDataIndex);
- ExtractFromXML(nullptr, nRawData, nRawDataIndex, "");
+ ExtractFromFile(nRawData, nRawDataIndex, "");
+ DeclareVar("", "");
}
void ZMtx::ParseRawData()
diff --git a/ZAPD/ZResource.cpp b/ZAPD/ZResource.cpp
index f96361e..9ffcc74 100644
--- a/ZAPD/ZResource.cpp
+++ b/ZAPD/ZResource.cpp
@@ -27,8 +27,14 @@ void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<u
ParseRawData();
}
-void ZResource::ExtractFromFile()
+void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, int nRawDataIndex,
+ const std::string& nRelPath)
{
+ rawData = nRawData;
+ rawDataIndex = nRawDataIndex;
+ relativePath = nRelPath;
+
+ ParseRawData();
}
void ZResource::ParseXML(tinyxml2::XMLElement* reader)
diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h
index 45052b6..3f39e85 100644
--- a/ZAPD/ZResource.h
+++ b/ZAPD/ZResource.h
@@ -58,7 +58,8 @@ public:
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const int nRawDataIndex,
const std::string& nRelPath); // Extract Mode
- virtual void ExtractFromFile();
+ virtual void ExtractFromFile(const std::vector<uint8_t>& nRawData, int nRawDataIndex,
+ const std::string& nRelPath);
// Misc
virtual void ParseXML(tinyxml2::XMLElement* reader);
diff --git a/ZAPD/ZRoom/Commands/SetActorList.cpp b/ZAPD/ZRoom/Commands/SetActorList.cpp
index 5ce8586..5e460f7 100644
--- a/ZAPD/ZRoom/Commands/SetActorList.cpp
+++ b/ZAPD/ZRoom/Commands/SetActorList.cpp
@@ -74,7 +74,7 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress)
{
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",
+ "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,
diff --git a/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/ZAPD/ZRoom/Commands/SetCutscenes.cpp
index 4c9a7e0..0ed124f 100644
--- a/ZAPD/ZRoom/Commands/SetCutscenes.cpp
+++ b/ZAPD/ZRoom/Commands/SetCutscenes.cpp
@@ -19,9 +19,14 @@ 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,
- ""); // TODO: Use ExtractFromFile() here when that gets implemented
+ cutscene->ExtractFromFile(rawData, segmentOffset, "");
+
+ auto decl = nZRoom->parent->GetDeclaration(segmentOffset);
+ if (decl == nullptr)
+ {
+ cutscene->DeclareVar(zRoom->GetName().c_str(), "");
+ }
+
cutscenes.push_back(cutscene);
}
else
@@ -59,29 +64,16 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD
for (ZCutsceneBase* cutscene : cutscenes)
{
- string output = "";
-
- output += cutscene->GetSourceOutputCode(zRoom->GetName());
-
if (cutscene->getSegmentOffset() != 0)
{
Declaration* decl = zRoom->parent->GetDeclaration(cutscene->getSegmentOffset());
if (decl == nullptr)
{
- DeclarationPadding padding = (Globals::Instance->game == ZGame::MM_RETAIL) ?
- 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()),
- 0, output);
+ cutscene->GetSourceOutputCode(zRoom->GetName());
}
else if (decl->text == "")
{
- decl->text = output;
+ decl->text = cutscene->GetBodySourceCode();
}
}
}
diff --git a/ZAPD/ZRoom/Commands/SetPathways.cpp b/ZAPD/ZRoom/Commands/SetPathways.cpp
index 7e3d49c..f15bf52 100644
--- a/ZAPD/ZRoom/Commands/SetPathways.cpp
+++ b/ZAPD/ZRoom/Commands/SetPathways.cpp
@@ -5,62 +5,83 @@
#include "../../ZFile.h"
#include "../ZRoom.h"
+REGISTER_ZFILENODE(Path, ZSetPathways);
+
using namespace std;
-SetPathways::SetPathways(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
- bool isFromHeader)
- : ZRoomCommand(nZRoom, rawData, rawDataIndex)
+ZSetPathways::ZSetPathways(ZFile* nParent) : ZResource(parent)
{
- _rawData = rawData;
- _rawDataIndex = rawDataIndex;
+}
- if (isFromHeader)
- segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
- else
- segmentOffset = _rawDataIndex;
+ZSetPathways::ZSetPathways(ZRoom* nZRoom, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
+ bool nIsFromHeader)
+ : ZResource(nZRoom->parent), ZRoomCommand(nZRoom, nRawData, nRawDataIndex)
+{
+ rawData = nRawData;
+ rawDataIndex = nRawDataIndex;
+ isFromHeader = nIsFromHeader;
+}
- if (segmentOffset != 0)
- zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
+ZSetPathways::~ZSetPathways()
+{
+ delete pathwayList;
}
-SetPathways::~SetPathways()
+void ZSetPathways::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
- if (pathwayList != nullptr)
- delete pathwayList;
+ parent->AddDeclaration(cmdAddress, DeclarationAlignment::None, 8,
+ StringHelper::Sprintf("static %s", GetCommandCName().c_str()),
+ StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(),
+ commandSet & 0x00FFFFFF, cmdIndex, cmdID),
+ StringHelper::Sprintf("%s // 0x%04X", bodyStr.c_str(), cmdAddress));
}
-string SetPathways::GetSourceOutputCode(std::string prefix)
+string ZSetPathways::GetSourceOutputCode(const std::string& prefix)
{
+ if (pathwayList != nullptr)
+ pathwayList->GetSourceOutputCode(parent->GetName());
+
return "";
}
-string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress)
+void ZSetPathways::ParseRawData()
{
+ if (isFromHeader)
+ segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
+ else
+ segmentOffset = rawDataIndex;
+
+ if (segmentOffset != 0)
+ parent->AddDeclarationPlaceholder(segmentOffset);
+
int numPaths = (Globals::Instance->game != ZGame::MM_RETAIL) ?
1 :
zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8;
- pathwayList = new PathwayList(zRoom, _rawData, segmentOffset, numPaths);
+ pathwayList = new PathwayList(parent, rawData, segmentOffset, numPaths);
+}
+string ZSetPathways::GenerateSourceCodePass1(string roomName, int baseAddress)
+{
+ ParseRawData();
return "";
}
-string SetPathways::GenerateSourceCodePass2(string roomName, int baseAddress)
+string ZSetPathways::GenerateSourceCodePass2(string roomName, int baseAddress)
{
string sourceOutput = "";
- sourceOutput +=
- StringHelper::Sprintf("%s 0, (u32)%sPathway0x%06X };",
- ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
- roomName.c_str(), segmentOffset);
+ sourceOutput += StringHelper::Sprintf("%s 0, (u32)%sPathway0x%06X };",
+ ZRoomCommand::GenerateSourceCodePass1("", 0).c_str(),
+ parent->GetName().c_str(), segmentOffset);
if (pathwayList != nullptr)
- pathwayList->GetSourceOutputCode(roomName);
+ pathwayList->GetSourceOutputCode(parent->GetName());
return sourceOutput;
}
-int32_t SetPathways::GetRawDataSize()
+int32_t ZSetPathways::GetRawDataSize()
{
int32_t size = 0;
if (pathwayList != nullptr)
@@ -69,20 +90,20 @@ int32_t SetPathways::GetRawDataSize()
return ZRoomCommand::GetRawDataSize() + size;
}
-string SetPathways::GenerateExterns()
+string ZSetPathways::GenerateExterns()
{
if (pathwayList != nullptr)
- return pathwayList->GenerateExterns();
+ return pathwayList->GenerateExterns(parent->GetName());
- return std::string();
+ return "";
}
-string SetPathways::GetCommandCName()
+string ZSetPathways::GetCommandCName()
{
return "SCmdPathList";
}
-RoomCommand SetPathways::GetRoomCommand()
+RoomCommand ZSetPathways::GetRoomCommand()
{
return RoomCommand::SetPathways;
}
@@ -117,9 +138,9 @@ PathwayEntry::PathwayEntry(std::vector<uint8_t> rawData, int rawDataIndex)
}
}
-PathwayList::PathwayList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, int length)
+PathwayList::PathwayList(ZFile* nParent, std::vector<uint8_t> rawData, int rawDataIndex, int length)
{
- zRoom = nZRoom;
+ parent = nParent;
_rawDataIndex = rawDataIndex;
uint32_t currentPtr = rawDataIndex;
@@ -143,7 +164,7 @@ PathwayList::~PathwayList()
delete path;
}
-void PathwayList::GetSourceOutputCode(std::string prefix)
+void PathwayList::GetSourceOutputCode(const std::string& prefix)
{
{
string declaration = "";
@@ -165,7 +186,7 @@ void PathwayList::GetSourceOutputCode(std::string prefix)
index++;
}
- zRoom->parent->AddDeclarationArray(
+ parent->AddDeclarationArray(
_rawDataIndex, DeclarationAlignment::None, DeclarationPadding::None,
pathways.size() * 8, "Path",
StringHelper::Sprintf("%sPathway0x%06X", prefix.c_str(), _rawDataIndex),
@@ -188,7 +209,7 @@ void PathwayList::GetSourceOutputCode(std::string prefix)
index++;
}
- zRoom->parent->AddDeclarationArray(
+ parent->AddDeclarationArray(
entry->listSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad4,
entry->points.size() * 6, "Vec3s",
StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(), entry->listSegmentOffset),
@@ -208,13 +229,13 @@ int32_t PathwayList::GetRawDataSize()
return pathways.size() * 8 + pointsSize;
}
-string PathwayList::GenerateExterns()
+string PathwayList::GenerateExterns(const std::string& prefix)
{
string declaration = "";
for (PathwayEntry* entry : pathways)
{
declaration += StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n",
- zRoom->GetName().c_str(), entry->listSegmentOffset);
+ prefix.c_str(), entry->listSegmentOffset);
}
return declaration;
diff --git a/ZAPD/ZRoom/Commands/SetPathways.h b/ZAPD/ZRoom/Commands/SetPathways.h
index 8e1a00f..67dc527 100644
--- a/ZAPD/ZRoom/Commands/SetPathways.h
+++ b/ZAPD/ZRoom/Commands/SetPathways.h
@@ -2,6 +2,7 @@
#include "../../Vec3s.h"
#include "../ZRoomCommand.h"
+#include "ZResource.h"
class PathwayEntry
{
@@ -20,37 +21,42 @@ public:
struct PathwayList
{
public:
- PathwayList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, int length);
+ PathwayList(ZFile* nParent, std::vector<uint8_t> rawData, int rawDataIndex, int length);
~PathwayList();
- void GetSourceOutputCode(std::string prefix);
+ void GetSourceOutputCode(const std::string& prefix);
int32_t GetRawDataSize();
- std::string GenerateExterns();
+ std::string GenerateExterns(const std::string& prefix);
private:
- ZRoom* zRoom;
+ ZFile* parent;
std::vector<PathwayEntry*> pathways;
std::vector<uint8_t> _rawData;
int _rawDataIndex;
};
-class SetPathways : public ZRoomCommand
+class ZSetPathways : public ZResource, public ZRoomCommand
{
public:
- SetPathways(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, bool isFromHeader);
- ~SetPathways();
+ ZSetPathways(ZFile* nParent);
+ ZSetPathways(ZRoom* nZRoom, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
+ bool nIsFromHeader);
+ ~ZSetPathways();
- std::string GetSourceOutputCode(std::string prefix);
- virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress);
- virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress);
- virtual RoomCommand GetRoomCommand();
- virtual int32_t GetRawDataSize();
- virtual std::string GetCommandCName();
- virtual std::string GenerateExterns();
+ void ParseRawData() override;
+
+ void DeclareVar(const std::string& prefix, const std::string& bodyStr);
+ std::string GetSourceOutputCode(const std::string& prefix) override;
+
+ std::string GenerateSourceCodePass1(std::string roomName, int baseAddress) override;
+ std::string GenerateSourceCodePass2(std::string roomName, int baseAddress) override;
+ RoomCommand GetRoomCommand() override;
+ int32_t GetRawDataSize() override;
+ std::string GetCommandCName() override;
+ std::string GenerateExterns() override;
private:
uint32_t segmentOffset;
PathwayList* pathwayList;
- std::vector<uint8_t> _rawData;
- int _rawDataIndex;
+ bool isFromHeader = false;
}; \ No newline at end of file
diff --git a/ZAPD/ZRoom/ZRoom.cpp b/ZAPD/ZRoom/ZRoom.cpp
index 2eff08a..7876d74 100644
--- a/ZAPD/ZRoom/ZRoom.cpp
+++ b/ZAPD/ZRoom/ZRoom.cpp
@@ -115,27 +115,6 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8
dList->GetSourceOutputCode(name);
delete dList;
}
- else if (string(child->Name()) == "BlobHint")
- {
- string addressStr = child->Attribute("Offset");
- int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16);
-
- string sizeStr = child->Attribute("Size");
- int size = strtol(StringHelper::Split(sizeStr, "0x")[1].c_str(), NULL, 16);
-
- ZBlob* blob =
- new ZBlob(rawData, address, size,
- StringHelper::Sprintf("%sBlob0x%06X", name.c_str(), address), parent);
-
- if (child->Attribute("Name") != NULL)
- childName = string(child->Attribute("Name"));
- else
- childName = StringHelper::Sprintf("%s_%s", name.c_str(), blob->GetName().c_str());
-
- parent->AddDeclarationArray(address, DeclarationAlignment::None, blob->GetRawDataSize(),
- "u8", childName, 0, blob->GetSourceOutputCode(name));
- delete blob;
- }
else if (string(child->Name()) == "CutsceneHint")
{
string addressStr = child->Attribute("Offset");
@@ -143,19 +122,10 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8
// ZCutscene* cutscene = new ZCutscene(rawData, address, 9999, parent);
ZCutscene* cutscene = new ZCutscene(parent);
- cutscene->ExtractFromXML(
- nullptr, rawData, address,
- ""); // TODO: Make this use ExtractFromFile() once that's been implemented
+ cutscene->ExtractFromXML(child, rawData, address, "");
- if (child->Attribute("Name") != NULL)
- childName = string(child->Attribute("Name"));
- else
- childName = StringHelper::Sprintf("%sCutsceneData0x%06X", name.c_str(),
- cutscene->GetRawDataIndex());
+ cutscene->GetSourceOutputCode(name);
- parent->AddDeclarationArray(address, DeclarationAlignment::None,
- DeclarationPadding::Pad16, cutscene->GetRawDataSize(),
- "s32", childName, 0, cutscene->GetSourceOutputCode(name));
delete cutscene;
}
else if (string(child->Name()) == "AltHeaderHint")
@@ -178,43 +148,19 @@ 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);
- SetPathways* pathway = new SetPathways(this, rawData, address, false);
+ ZSetPathways* pathway = new ZSetPathways(this, rawData, address, false);
pathway->GenerateSourceCodePass1(name, 0);
pathway->GenerateSourceCodePass2(name, 0);
delete pathway;
}
- else if (string(child->Name()) == "TextureHint")
- {
- string addressStr = child->Attribute("Offset");
- int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16);
-
- string typeStr = child->Attribute("Type");
- int width = strtol(string(child->Attribute("Width")).c_str(), NULL, 10);
- int height = strtol(string(child->Attribute("Height")).c_str(), NULL, 10);
-
- ZTexture* tex = ZTexture::FromBinary(
- ZTexture::GetTextureTypeFromString(typeStr), rawData, address,
- StringHelper::Sprintf("%sTex_%06X", name.c_str(), address), width, height, parent);
- parent->AddDeclarationArray(address, DeclarationAlignment::None, tex->GetRawDataSize(),
- "u64", StringHelper::Sprintf("%s", tex->GetName().c_str()),
- 0, tex->GetSourceOutputCode(name));
- delete tex;
- }
- else if (string(child->Name()) == "BackgroundHint")
- {
- string comment = "";
- if (child->Attribute("Comment") != NULL)
- comment = "// " + string(child->Attribute("Comment")) + "\n";
-
- string addressStr = child->Attribute("Offset");
- int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16);
-
- ZBackground* back = new ZBackground(parent);
- back->ExtractFromXML(reader, rawData, address, "");
- parent->resources.push_back(back);
- }
+ fprintf(stderr,
+ "ZRoom::ExtractFromXML: Deprecation warning in '%s'.\n"
+ "\t The resource '%s' is currently deprecated, and will be removed in a future "
+ "version.\n"
+ "\t Use the non-hint version instead.\n",
+ name.c_str(), child->Name());
}
// ParseCommands(rawDataIndex);
@@ -226,7 +172,7 @@ void ZRoom::ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet co
{
bool shouldContinue = true;
int currentIndex = 0;
- int rawDataIndex = commandSet.address & 0x00FFFFFF;
+ int rawDataIndex = GETSEGOFFSET(commandSet.address);
int32_t commandsLeft = commandSet.commandCount;
@@ -283,7 +229,7 @@ void ZRoom::ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet co
cmd = new SetLightList(this, rawData, rawDataIndex);
break; // 0x0C (MM-ONLY)
case RoomCommand::SetPathways:
- cmd = new SetPathways(this, rawData, rawDataIndex, true);
+ cmd = new ZSetPathways(this, rawData, rawDataIndex, true);
break; // 0x0D
case RoomCommand::SetTransitionActorList:
cmd = new SetTransitionActorList(this, rawData, rawDataIndex);
diff --git a/ZAPD/ZRoom/ZRoomCommand.h b/ZAPD/ZRoom/ZRoomCommand.h
index fcc554a..d5ae77b 100644
--- a/ZAPD/ZRoom/ZRoomCommand.h
+++ b/ZAPD/ZRoom/ZRoomCommand.h
@@ -56,6 +56,7 @@ public:
int32_t cmdSet;
uint32_t commandSet;
+ ZRoomCommand() = default;
ZRoomCommand(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex);
virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress);