From d06fb101439a7e5de28bb824b70992f97d91b54a Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Thu, 6 Jan 2022 23:24:29 -0500 Subject: Array exporter updated to be a bit more flexible. Cutscene exporter added (thanks Louist) Path Exporter added (untested) DList fixes --- OTRExporter/ArrayExporter.cpp | 59 +++++++++++++++++++++++++++++---- OTRExporter/CutsceneExporter.cpp | 26 +++++++++++---- OTRExporter/DisplayListExporter.cpp | 24 ++++++++++++-- OTRExporter/Main.cpp | 2 ++ OTRExporter/OTRExporter.vcxproj | 2 ++ OTRExporter/OTRExporter.vcxproj.filters | 6 ++++ OTRExporter/PathExporter.cpp | 18 ++++++++++ OTRExporter/PathExporter.h | 12 +++++++ OTRExporter/RoomExporter.cpp | 34 ++++++++++++++++++- 9 files changed, 166 insertions(+), 17 deletions(-) create mode 100644 OTRExporter/PathExporter.cpp create mode 100644 OTRExporter/PathExporter.h diff --git a/OTRExporter/ArrayExporter.cpp b/OTRExporter/ArrayExporter.cpp index 0fc097c..7fc73fa 100644 --- a/OTRExporter/ArrayExporter.cpp +++ b/OTRExporter/ArrayExporter.cpp @@ -3,13 +3,60 @@ void OTRExporter_Array::Save(ZResource* res, fs::path outPath, BinaryWriter* writer) { ZArray* arr = (ZArray*)res; - //There has to be a better way - if (arr->resList[0]->GetResourceType() == ZResourceType::Vertex) { - OTRExporter_Vtx exporter; - exporter.SaveArr(arr->resList,writer); - //exporter.count = arr->arrayCnt; - //exporter.Save(res, outPath, writer); + WriteHeader(res, outPath, writer, OtrLib::ResourceType::OTRArray); + + writer->Write((uint32_t)arr->resList[0]->GetResourceType()); + writer->Write((uint32_t)arr->arrayCnt); + + for (int i = 0; i < arr->arrayCnt; i++) + { + ZScalar* scal = (ZScalar*)arr->resList[i]; + + writer->Write((uint32_t)scal->scalarType); + + switch (scal->scalarType) + { + case ZScalarType::ZSCALAR_U8: + writer->Write(scal->scalarData.u8); + break; + case ZScalarType::ZSCALAR_S8: + writer->Write(scal->scalarData.s8); + break; + case ZScalarType::ZSCALAR_U16: + writer->Write(scal->scalarData.u16); + break; + case ZScalarType::ZSCALAR_S16: + writer->Write(scal->scalarData.s16); + break; + case ZScalarType::ZSCALAR_S32: + writer->Write(scal->scalarData.s32); + break; + case ZScalarType::ZSCALAR_U32: + writer->Write(scal->scalarData.u32); + break; + case ZScalarType::ZSCALAR_S64: + writer->Write(scal->scalarData.s64); + break; + case ZScalarType::ZSCALAR_U64: + writer->Write(scal->scalarData.u64); + break; + // OTRTODO: ADD OTHER TYPES + } } + + ////There has to be a better way™ + //if (arr->resList[0]->GetResourceType() == ZResourceType::Vertex) + //{ + // OTRExporter_Vtx exporter; + // exporter.SaveArr(arr->resList,writer); + + // //exporter.count = arr->arrayCnt; + // //exporter.Save(res, outPath, writer); + //} + //else if (arr->resList[0]->GetResourceType() == ZResourceType::Vector) + //{ + // WriteHeader(res, outPath, writer, OtrLib::ResourceType::OTRVtx); + //} } \ No newline at end of file diff --git a/OTRExporter/CutsceneExporter.cpp b/OTRExporter/CutsceneExporter.cpp index 63e5775..a39505e 100644 --- a/OTRExporter/CutsceneExporter.cpp +++ b/OTRExporter/CutsceneExporter.cpp @@ -10,11 +10,17 @@ void OTRExporter_Cutscene::Save(ZResource* res, fs::path outPath, BinaryWriter* writer->Write((uint32_t)OtrLib::OTRVersion::Deckard); writer->Write((uint64_t)0xDEADBEEFDEADBEEF); // id + //writer->Write((uint32_t)cs->commands.size() + 2 + 2); + writer->Write((uint32_t)0); + + int currentStream = writer->GetBaseAddress(); + writer->Write(CS_BEGIN_CUTSCENE(cs->numCommands, cs->endFrame)); - for (size_t i = 0; i < cs->commands.size(); i++) + for (size_t i = 0; i < cs->commands.size(); i++) { - switch ((CutsceneCommands)cs->commands[i]->commandID) { + switch ((CutsceneCommands)cs->commands[i]->commandID) + { case CutsceneCommands::SetCameraPos: { writer->Write(CS_CMD_CAM_EYE); @@ -176,6 +182,8 @@ void OTRExporter_Cutscene::Save(ZResource* res, fs::path outPath, BinaryWriter* } case CutsceneCommands::SetSceneTransFX: { + CutsceneCommandSceneTransFX* cmdTFX = (CutsceneCommandSceneTransFX*)cs->commands[i]; + writer->Write(CS_CMD_SCENE_TRANS_FX); writer->Write((uint32_t)1); writer->Write(CMD_HH((((CutsceneCommandSceneTransFX*)cs->commands[i])->base), ((CutsceneCommandSceneTransFX*)cs->commands[i])->startFrame)); @@ -268,11 +276,15 @@ void OTRExporter_Cutscene::Save(ZResource* res, fs::path outPath, BinaryWriter* writer->Write(CMD_HH(((CutsceneCommandTerminator*)cs->commands[i])->endFrame, ((CutsceneCommandTerminator*)cs->commands[i])->endFrame)); break; } - - //CS_END - writer->Write(0xFFFFFFFF); - writer->Write((uint32_t)0); } - } + + //CS_END + writer->Write(0xFFFFFFFF); + writer->Write((uint32_t)0); + + int endStream = writer->GetBaseAddress(); + writer->Seek(currentStream - 4, SeekOffsetType::Start); + writer->Write((uint32_t)((endStream - currentStream) / 4)); + writer->Seek(endStream, SeekOffsetType::Start); } \ No newline at end of file diff --git a/OTRExporter/DisplayListExporter.cpp b/OTRExporter/DisplayListExporter.cpp index be0dded..546da76 100644 --- a/OTRExporter/DisplayListExporter.cpp +++ b/OTRExporter/DisplayListExporter.cpp @@ -98,6 +98,17 @@ void OTRExporter_DisplayList::Save(ZResource* res, fs::path outPath, BinaryWrite word1 = value.words.w1; } break; + case G_MODIFYVTX: + { + int32_t ww = (data & 0x00FF000000000000ULL) >> 48; + int32_t nnnn = (data & 0x0000FFFF00000000ULL) >> 32; + int32_t vvvvvvvv = (data & 0x00000000FFFFFFFFULL); + + Gfx value = gsSPModifyVertex(nnnn / 2, ww, vvvvvvvv); + word0 = value.words.w0; + word1 = value.words.w1; + } + break; default: { printf("Undefined opcode: %02X\n", opcode); @@ -318,11 +329,18 @@ void OTRExporter_DisplayList::Save(ZResource* res, fs::path outPath, BinaryWrite word1 = test.words.w1; } break; - /*case G_QUAD: + case G_QUAD: { - gsSP1Quadrangle() + int32_t aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; + int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; + int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; + int32_t dd = ((data & 0x000000000000FFULL)) / 2; + + Gfx test = gsSP1Quadrangle(aa, bb, cc, dd, 0); + word0 = test.words.w0; + word1 = test.words.w1; } - break;*/ + break; case G_SETPRIMCOLOR: { int32_t mm = (data & 0x0000FF0000000000) >> 40; diff --git a/OTRExporter/Main.cpp b/OTRExporter/Main.cpp index 7f3e644..16db56f 100644 --- a/OTRExporter/Main.cpp +++ b/OTRExporter/Main.cpp @@ -12,6 +12,7 @@ #include "VtxExporter.h" #include "AnimationExporter.h" #include "CutsceneExporter.h" +#include "PathExporter.h" #include #include #include @@ -182,6 +183,7 @@ static void ImportExporters() exporterSet->exporters[ZResourceType::Cutscene] = new OTRExporter_Cutscene(); exporterSet->exporters[ZResourceType::Vertex] = new OTRExporter_Vtx(); exporterSet->exporters[ZResourceType::Array] = new OTRExporter_Array(); + exporterSet->exporters[ZResourceType::Path] = new OTRExporter_Path(); Globals::AddExporter("OTR", exporterSet); } diff --git a/OTRExporter/OTRExporter.vcxproj b/OTRExporter/OTRExporter.vcxproj index 272913d..ddaa07f 100644 --- a/OTRExporter/OTRExporter.vcxproj +++ b/OTRExporter/OTRExporter.vcxproj @@ -30,6 +30,7 @@ + @@ -48,6 +49,7 @@ + diff --git a/OTRExporter/OTRExporter.vcxproj.filters b/OTRExporter/OTRExporter.vcxproj.filters index c93ed03..eff628c 100644 --- a/OTRExporter/OTRExporter.vcxproj.filters +++ b/OTRExporter/OTRExporter.vcxproj.filters @@ -66,6 +66,9 @@ Header Files + + Header Files + @@ -110,5 +113,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/OTRExporter/PathExporter.cpp b/OTRExporter/PathExporter.cpp new file mode 100644 index 0000000..ed00646 --- /dev/null +++ b/OTRExporter/PathExporter.cpp @@ -0,0 +1,18 @@ +#include "PathExporter.h" +#include "../ZAPD/ZFile.h" + +void OTRExporter_Path::Save(ZResource* res, fs::path outPath, BinaryWriter* writer) +{ + ZPath* path = (ZPath*)res; + + WriteHeader(res, outPath, writer, OtrLib::ResourceType::OTRPath); + + writer->Write((uint32_t)path->pathways[0].points.size()); + + for (int i = 0; i < path->pathways[0].points.size(); i++) + { + writer->Write(path->pathways[0].points[i].scalars[0].scalarData.s16); + writer->Write(path->pathways[0].points[i].scalars[1].scalarData.s16); + writer->Write(path->pathways[0].points[i].scalars[2].scalarData.s16); + } +} \ No newline at end of file diff --git a/OTRExporter/PathExporter.h b/OTRExporter/PathExporter.h new file mode 100644 index 0000000..50beb08 --- /dev/null +++ b/OTRExporter/PathExporter.h @@ -0,0 +1,12 @@ +#pragma once + +#include "ZResource.h" +#include "ZPath.h" +#include "OTRExporter.h" +#include + +class OTRExporter_Path : public OTRExporter +{ +public: + virtual void Save(ZResource* res, const fs::path outPath, BinaryWriter* writer) override; +}; \ No newline at end of file diff --git a/OTRExporter/RoomExporter.cpp b/OTRExporter/RoomExporter.cpp index 07e448a..5c62a81 100644 --- a/OTRExporter/RoomExporter.cpp +++ b/OTRExporter/RoomExporter.cpp @@ -30,6 +30,8 @@ #include "TextureExporter.h" #include "Main.h" #include +#include "CutsceneExporter.h" +#include #undef FindResource void OTRExporter_Room::Save(ZResource* res, const fs::path outPath, BinaryWriter* writer) @@ -48,6 +50,27 @@ void OTRExporter_Room::Save(ZResource* res, const fs::path outPath, BinaryWriter switch (cmd->cmdID) { + case RoomCommand::SetTransitionActorList: + { + SetTransitionActorList* cmdTrans = (SetTransitionActorList*)cmd; + + writer->Write((uint32_t)cmdTrans->transitionActors.size()); + + for (const TransitionActorEntry& entry : cmdTrans->transitionActors) + { + writer->Write(entry.frontObjectRoom); + writer->Write(entry.frontTransitionReaction); + writer->Write(entry.backObjectRoom); + writer->Write(entry.backTransitionReaction); + writer->Write(entry.actorNum); + writer->Write(entry.posX); + writer->Write(entry.posY); + writer->Write(entry.posZ); + writer->Write(entry.rotY); + writer->Write(entry.initVar); + } + } + break; case RoomCommand::SetActorList: { SetActorList* cmdSetActorList = (SetActorList*)cmd; @@ -424,7 +447,16 @@ void OTRExporter_Room::Save(ZResource* res, const fs::path outPath, BinaryWriter std::string listName; Globals::Instance->GetSegmentedPtrName(cmdSetCutscenes->cmdArg2, room->parent, "CutsceneData", listName); - writer->Write(listName); + std::string fName = StringHelper::Sprintf("%s\\%s", OTRExporter_DisplayList::GetParentFolderName(room).c_str(), listName.c_str()); + writer->Write(fName); + + MemoryStream* csStream = new MemoryStream(); + BinaryWriter csWriter = BinaryWriter(csStream); + OTRExporter_Cutscene cs; + cs.Save(cmdSetCutscenes->cutscenes[0], "", &csWriter); + + //std::string fName = OTRExporter_DisplayList::GetPathToRes(res, vtxDecl->varName); + otrArchive->AddFile(fName, (uintptr_t)csStream->ToVector().data(), csWriter.GetBaseAddress()); } break; case RoomCommand::EndMarker: -- cgit v1.2.3