From 5c12399c80ccdff8332cede991467eda048134ed Mon Sep 17 00:00:00 2001 From: louist103 <35883445+louist103@users.noreply.github.com> Date: Sat, 25 Nov 2023 19:28:39 -0500 Subject: Importer/exporter fixes. --- OTRExporter | 2 +- mm/2s2h/resource/importer/SceneFactory.cpp | 2 +- .../scenecommand/SetCameraSettingsFactory.cpp | 6 ++-- .../importer/scenecommand/SetCsCameraFactory.cpp | 6 ++-- .../scenecommand/SetRoomBehaviorFactory.cpp | 40 ++++++++++++++++++++++ .../importer/scenecommand/SetRoomBehaviorFactory.h | 12 +++++++ mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp | 2 +- .../resource/type/scenecommand/SetRoomBehavior.cpp | 6 ++++ .../resource/type/scenecommand/SetRoomBehavior.h | 21 ++++++++++++ mm/2s2h/z_scene_2SH.cpp | 18 ++++++---- 10 files changed, 100 insertions(+), 15 deletions(-) diff --git a/OTRExporter b/OTRExporter index ff843858c..a2df4dda0 160000 --- a/OTRExporter +++ b/OTRExporter @@ -1 +1 @@ -Subproject commit ff843858ce5b853fb2cd19d9cf81009859bbc5bb +Subproject commit a2df4dda0a1f7adfa08d81242e32a9665e1d35b4 diff --git a/mm/2s2h/resource/importer/SceneFactory.cpp b/mm/2s2h/resource/importer/SceneFactory.cpp index 0e93da4f6..67320daa8 100644 --- a/mm/2s2h/resource/importer/SceneFactory.cpp +++ b/mm/2s2h/resource/importer/SceneFactory.cpp @@ -45,7 +45,7 @@ SceneFactory::ReadResource(std::shared_ptr initData, std::shar SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetEchoSettings] = std::make_shared(); SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetSoundSettings] = std::make_shared(); SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetSkyboxSettings] = std::make_shared(); - SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetRoomBehavior] = std::make_shared(); + SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetRoomBehavior] = std::make_shared(); SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetCsCamera] = std::make_shared(); SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetCameraSettings] = std::make_shared(); SceneFactory::sceneCommandFactories[LUS::SceneCommandID::SetRoomList] = std::make_shared(); diff --git a/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.cpp index d36d412e9..caa46cefd 100644 --- a/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.cpp +++ b/mm/2s2h/resource/importer/scenecommand/SetCameraSettingsFactory.cpp @@ -31,9 +31,9 @@ void LUS::SetCameraSettingsFactoryV0::ParseFileBinary(std::shared_ptrsettings.cameraMovement = reader->ReadInt8(); - setCameraSettings->settings.worldMapArea = reader->ReadInt32(); + // BENTODO in MM this scene command is only used as a signal to have the scene system mark an area as visted. We should make a new command factory for this but this is fine for now. + //setCameraSettings->settings.cameraMovement = reader->ReadInt8(); + //setCameraSettings->settings.worldMapArea = reader->ReadInt32(); } } // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.cpp index 4e7c74067..445f64cb6 100644 --- a/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.cpp +++ b/mm/2s2h/resource/importer/scenecommand/SetCsCameraFactory.cpp @@ -43,9 +43,9 @@ void LUS::SetCsCameraFactoryV0::ParseFileBinary(std::shared_ptr re } data.actorCsCamFuncData = new z64Vec3s[data.count]; for (size_t j = 0; j < data.count; j++) { - data.actorCsCamFuncData->x = reader->ReadInt16(); - data.actorCsCamFuncData->y = reader->ReadInt16(); - data.actorCsCamFuncData->z = reader->ReadInt16(); + data.actorCsCamFuncData[j].x = reader->ReadInt16(); + data.actorCsCamFuncData[j].y = reader->ReadInt16(); + data.actorCsCamFuncData[j].z = reader->ReadInt16(); } setCsCamera->csCamera.emplace_back(data); } diff --git a/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp index 6222eb3b6..e2c5df85f 100644 --- a/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp +++ b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp @@ -3,6 +3,8 @@ #include "spdlog/spdlog.h" namespace LUS { +// OOT +#if 0 std::shared_ptr SetRoomBehaviorFactory::ReadResource(std::shared_ptr initData, std::shared_ptr reader) { auto resource = std::make_shared(initData); @@ -34,5 +36,43 @@ void LUS::SetRoomBehaviorFactoryV0::ParseFileBinary(std::shared_ptrroomBehavior.gameplayFlags = reader->ReadInt8(); setRoomBehavior->roomBehavior.gameplayFlags2 = reader->ReadInt32(); } +#endif +// MM + +std::shared_ptr SetRoomBehaviorMMFactory::ReadResource(std::shared_ptr initData, + std::shared_ptr reader) { + auto resource = std::make_shared(initData); + std::shared_ptr factory = nullptr; + + switch (resource->GetInitData()->ResourceVersion) { + case 0: + factory = std::make_shared(); + break; + } + + if (factory == nullptr) { + SPDLOG_ERROR("Failed to load SetRoomBehavior with version {}", resource->GetInitData()->ResourceVersion); + return nullptr; + } + + factory->ParseFileBinary(reader, resource); + + return resource; +} + +void SetRoomBehaviorMMFactoryV0::ParseFileBinary(std::shared_ptr reader, + std::shared_ptr resource) { + std::shared_ptr setRoomBehavior = std::static_pointer_cast(resource); + ResourceVersionFactory::ParseFileBinary(reader, setRoomBehavior); + + ReadCommandId(setRoomBehavior, reader); + + setRoomBehavior->roomBehavior.gameplayFlags = reader->ReadInt8(); + setRoomBehavior->roomBehavior.currRoomUnk2 = reader->ReadInt8(); + setRoomBehavior->roomBehavior.currRoomUnk5 = reader->ReadInt8(); + setRoomBehavior->roomBehavior.msgCtxUnk = reader->ReadInt8(); + setRoomBehavior->roomBehavior.enablePointLights = reader->ReadInt8(); + setRoomBehavior->roomBehavior.kankyoContextUnkE2 = reader->ReadInt8(); +} } // namespace LUS diff --git a/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h index de812249d..a449a1c8f 100644 --- a/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h +++ b/mm/2s2h/resource/importer/scenecommand/SetRoomBehaviorFactory.h @@ -13,4 +13,16 @@ class SetRoomBehaviorFactoryV0 : public SceneCommandVersionFactory { public: void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; }; + +class SetRoomBehaviorMMFactory : public SceneCommandFactory { + public: + std::shared_ptr ReadResource(std::shared_ptr initData, + std::shared_ptr reader) override; +}; + +class SetRoomBehaviorMMFactoryV0 : public SceneCommandVersionFactory { + public: + void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; +}; + }; // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp b/mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp index 186ffcae6..59af0c0fe 100644 --- a/mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp +++ b/mm/2s2h/resource/type/scenecommand/SetCsCamera.cpp @@ -4,7 +4,7 @@ namespace LUS { SetCsCamera::~SetCsCamera() { for (auto c : csCamera) { if (c.actorCsCamFuncData != nullptr) { - delete c.actorCsCamFuncData; + delete[] c.actorCsCamFuncData; } } } diff --git a/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.cpp b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.cpp index deababc87..a56562449 100644 --- a/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.cpp +++ b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.cpp @@ -8,4 +8,10 @@ RoomBehavior* SetRoomBehavior::GetPointer() { size_t SetRoomBehavior::GetPointerSize() { return sizeof(RoomBehavior); } +RoomBehaviorMM* SetRoomBehaviorMM::GetPointer() { + return &roomBehavior; +} +size_t SetRoomBehaviorMM::GetPointerSize() { + return sizeof(RoomBehaviorMM); +} } // namespace LUS diff --git a/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.h b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.h index c2a28176e..6889a2aee 100644 --- a/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.h +++ b/mm/2s2h/resource/type/scenecommand/SetRoomBehavior.h @@ -13,6 +13,15 @@ typedef struct { int32_t gameplayFlags2; } RoomBehavior; +typedef struct { + int8_t gameplayFlags; + int8_t currRoomUnk2; + int8_t currRoomUnk5; + int8_t msgCtxUnk; + int8_t enablePointLights; + int8_t kankyoContextUnkE2; +} RoomBehaviorMM; + class SetRoomBehavior : public SceneCommand { public: using SceneCommand::SceneCommand; @@ -22,4 +31,16 @@ class SetRoomBehavior : public SceneCommand { RoomBehavior roomBehavior; }; + + +class SetRoomBehaviorMM : public SceneCommand { + public: + using SceneCommand::SceneCommand; + + RoomBehaviorMM* GetPointer(); + size_t GetPointerSize(); + + RoomBehaviorMM roomBehavior; +}; + }; // namespace LUS diff --git a/mm/2s2h/z_scene_2SH.cpp b/mm/2s2h/z_scene_2SH.cpp index 030ddcfa4..586d9d6b4 100644 --- a/mm/2s2h/z_scene_2SH.cpp +++ b/mm/2s2h/z_scene_2SH.cpp @@ -119,14 +119,20 @@ void Scene_CommandSpecialFiles(PlayState* play, LUS::ISceneCommand* cmd) { } void Scene_CommandRoomBehavior(PlayState* play, LUS::ISceneCommand* cmd) { - LUS::SetRoomBehavior* behavior = (LUS::SetRoomBehavior*)cmd; + LUS::SetRoomBehaviorMM* behavior = (LUS::SetRoomBehaviorMM*)cmd; play->roomCtx.curRoom.behaviorType1 = behavior->roomBehavior.gameplayFlags; - play->roomCtx.curRoom.behaviorType2 = behavior->roomBehavior.gameplayFlags2 & 0xFF; - play->roomCtx.curRoom.lensMode = (behavior->roomBehavior.gameplayFlags2 >> 8) & 1; - play->msgCtx.unk12044 = (behavior->roomBehavior.gameplayFlags2 >> 0xA) & 1; - play->roomCtx.curRoom.enablePosLights = (behavior->roomBehavior.gameplayFlags2 >> 0xB) & 1; - play->envCtx.stormState = (behavior->roomBehavior.gameplayFlags2 >> 0xC) & 1; + play->roomCtx.curRoom.behaviorType2 = behavior->roomBehavior.currRoomUnk2; + play->roomCtx.curRoom.lensMode = behavior->roomBehavior.currRoomUnk5; + play->msgCtx.unk12044 = behavior->roomBehavior.msgCtxUnk; + play->roomCtx.curRoom.enablePosLights = behavior->roomBehavior.enablePointLights; + play->envCtx.stormState = behavior->roomBehavior.kankyoContextUnkE2; + //play->roomCtx.curRoom.behaviorType1 = behavior->roomBehavior.gameplayFlags; + //play->roomCtx.curRoom.behaviorType2 = behavior->roomBehavior.gameplayFlags2 & 0xFF; + //play->roomCtx.curRoom.lensMode = (behavior->roomBehavior.gameplayFlags2 >> 8) & 1; + //play->msgCtx.unk12044 = (behavior->roomBehavior.gameplayFlags2 >> 0xA) & 1; + //play->roomCtx.curRoom.enablePosLights = (behavior->roomBehavior.gameplayFlags2 >> 0xB) & 1; + //play->envCtx.stormState = (behavior->roomBehavior.gameplayFlags2 >> 0xC) & 1; } void Scene_Command09(PlayState* play, LUS::ISceneCommand* cmd) { -- cgit v1.2.3