2022-03-21 21:54:48 -04:00
|
|
|
#include "SetCutscenes.h"
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "Utils/BitConverter.h"
|
|
|
|
#include "Utils/StringHelper.h"
|
|
|
|
#include "ZFile.h"
|
|
|
|
#include "ZRoom/ZRoom.h"
|
|
|
|
|
|
|
|
SetCutscenes::SetCutscenes(ZFile* nParent) : ZRoomCommand(nParent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCutscenes::ParseRawData()
|
|
|
|
{
|
|
|
|
ZRoomCommand::ParseRawData();
|
|
|
|
|
|
|
|
numCutscenes = cmdArg1;
|
2023-05-07 19:58:50 -04:00
|
|
|
|
|
|
|
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
|
|
|
{
|
|
|
|
int32_t currentPtr = segmentOffset;
|
|
|
|
|
|
|
|
cutsceneEntries.reserve(numCutscenes);
|
|
|
|
for (uint8_t i = 0; i < numCutscenes; i++)
|
|
|
|
{
|
|
|
|
CutsceneEntry entry(parent->GetRawData(), currentPtr);
|
|
|
|
cutsceneEntries.push_back(entry);
|
|
|
|
currentPtr += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97)
|
2022-03-21 21:54:48 -04:00
|
|
|
{
|
|
|
|
ZCutscene* cutscene = new ZCutscene(parent);
|
|
|
|
cutscene->ExtractFromFile(segmentOffset);
|
|
|
|
|
|
|
|
auto decl = parent->GetDeclaration(segmentOffset);
|
|
|
|
if (decl == nullptr)
|
|
|
|
{
|
|
|
|
cutscene->DeclareVar(zRoom->GetName().c_str(), "");
|
|
|
|
}
|
|
|
|
|
|
|
|
cutscenes.push_back(cutscene);
|
|
|
|
}
|
2023-05-07 19:58:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetCutscenes::DeclareReferences(const std::string& prefix)
|
|
|
|
{
|
|
|
|
std::string varPrefix = name;
|
|
|
|
if (varPrefix == "")
|
|
|
|
varPrefix = prefix;
|
|
|
|
|
|
|
|
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
2022-03-21 21:54:48 -04:00
|
|
|
{
|
|
|
|
std::string declaration;
|
2023-05-07 19:58:50 -04:00
|
|
|
size_t i = 0;
|
2022-03-21 21:54:48 -04:00
|
|
|
|
2023-05-07 19:58:50 -04:00
|
|
|
for (const auto& entry : cutsceneEntries)
|
2022-03-21 21:54:48 -04:00
|
|
|
{
|
2023-05-07 19:58:50 -04:00
|
|
|
if (entry.segmentPtr != SEGMENTED_NULL &&
|
|
|
|
GETSEGNUM(entry.segmentPtr) == parent->segment)
|
|
|
|
{
|
|
|
|
offset_t csOffset = Seg2Filespace(entry.segmentPtr, parent->baseAddress);
|
|
|
|
if (!parent->HasDeclaration(csOffset))
|
|
|
|
{
|
|
|
|
auto* cutscene = new ZCutscene(parent);
|
|
|
|
cutscene->ExtractFromFile(csOffset);
|
|
|
|
cutscene->SetName(cutscene->GetDefaultName(varPrefix));
|
|
|
|
cutscene->DeclareVar(varPrefix, "");
|
|
|
|
cutscene->DeclareReferences(varPrefix);
|
|
|
|
parent->AddResource(cutscene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string csName;
|
|
|
|
Globals::Instance->GetSegmentedPtrName(entry.segmentPtr, parent, "CutsceneData",
|
|
|
|
csName, parent->workerID);
|
2022-03-21 21:54:48 -04:00
|
|
|
|
2023-05-07 19:58:50 -04:00
|
|
|
declaration +=
|
|
|
|
StringHelper::Sprintf(" { %s, 0x%04X, 0x%02X, 0x%02X },", csName.c_str(),
|
|
|
|
entry.exit, entry.entrance, entry.flag);
|
2022-03-21 21:54:48 -04:00
|
|
|
|
2023-05-07 19:58:50 -04:00
|
|
|
if (i + 1 < numCutscenes)
|
2022-03-21 21:54:48 -04:00
|
|
|
declaration += "\n";
|
|
|
|
|
2023-05-07 19:58:50 -04:00
|
|
|
i++;
|
2022-03-21 21:54:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4,
|
|
|
|
cutsceneEntries.size() * 8, "CutsceneEntry",
|
|
|
|
StringHelper::Sprintf("%sCutsceneEntryList_%06X",
|
|
|
|
zRoom->GetName().c_str(), segmentOffset),
|
|
|
|
cutsceneEntries.size(), declaration);
|
|
|
|
}
|
2023-05-07 19:58:50 -04:00
|
|
|
else
|
2022-03-21 21:54:48 -04:00
|
|
|
{
|
2023-05-07 19:58:50 -04:00
|
|
|
if (cmdArg2 != SEGMENTED_NULL && GETSEGNUM(cmdArg2) == parent->segment)
|
2022-03-21 21:54:48 -04:00
|
|
|
{
|
2023-05-07 19:58:50 -04:00
|
|
|
offset_t csOffset = Seg2Filespace(cmdArg2, parent->baseAddress);
|
|
|
|
if (!parent->HasDeclaration(csOffset))
|
2022-03-21 21:54:48 -04:00
|
|
|
{
|
2023-05-07 19:58:50 -04:00
|
|
|
auto* cutscene = new ZCutscene(parent);
|
|
|
|
cutscene->ExtractFromFile(csOffset);
|
|
|
|
cutscene->SetName(cutscene->GetDefaultName(varPrefix));
|
|
|
|
cutscene->DeclareVar(varPrefix, "");
|
|
|
|
cutscene->DeclareReferences(varPrefix);
|
|
|
|
parent->AddResource(cutscene);
|
2022-03-21 21:54:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SetCutscenes::GetBodySourceCode() const
|
|
|
|
{
|
|
|
|
std::string listName;
|
2022-03-31 19:42:44 -04:00
|
|
|
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneData", listName,
|
|
|
|
parent->workerID);
|
2022-03-21 21:54:48 -04:00
|
|
|
|
|
|
|
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
2023-05-07 19:58:50 -04:00
|
|
|
{
|
|
|
|
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneEntry", listName,
|
|
|
|
parent->workerID);
|
2022-03-21 21:54:48 -04:00
|
|
|
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes,
|
|
|
|
listName.c_str());
|
2023-05-07 19:58:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneData", listName,
|
|
|
|
parent->workerID);
|
2022-03-21 21:54:48 -04:00
|
|
|
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_DATA(%s)", listName.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SetCutscenes::GetCommandCName() const
|
|
|
|
{
|
|
|
|
return "SCmdCutsceneData";
|
|
|
|
}
|
|
|
|
|
|
|
|
RoomCommand SetCutscenes::GetRoomCommand() const
|
|
|
|
{
|
|
|
|
return RoomCommand::SetCutscenes;
|
|
|
|
}
|
|
|
|
|
|
|
|
CutsceneEntry::CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
2023-05-07 19:58:50 -04:00
|
|
|
: segmentPtr(BitConverter::ToInt32BE(rawData, rawDataIndex + 0)),
|
2022-03-21 21:54:48 -04:00
|
|
|
exit(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), entrance(rawData[rawDataIndex + 6]),
|
|
|
|
flag(rawData[rawDataIndex + 7])
|
|
|
|
{
|
|
|
|
}
|