diff --git a/OTRExporter b/OTRExporter index d8f3c4dd4..bfb5bc697 160000 --- a/OTRExporter +++ b/OTRExporter @@ -1 +1 @@ -Subproject commit d8f3c4dd4a46fb46c4f69cd387afadfa711606e9 +Subproject commit bfb5bc6971f6f39c48a2642c0fa889ad2e6dd81e diff --git a/libultraship b/libultraship index 825bd1275..a5d269dc4 160000 --- a/libultraship +++ b/libultraship @@ -1 +1 @@ -Subproject commit 825bd1275bc26a8532f07a887db5141cd635df13 +Subproject commit a5d269dc484451170183515a079d3419deac3bd5 diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 62a8bdd3d..a4409ff8e 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -92,6 +92,7 @@ GameInteractorSail* GameInteractorSail::Instance; #include // Resource Types/Factories +#include "soh/resource/type/SohResourceType.h" #include "soh/resource/type/Animation.h" #include "soh/resource/type/AudioSample.h" #include "soh/resource/type/AudioSequence.h" @@ -319,19 +320,21 @@ OTRGlobals::OTRGlobals() { SPDLOG_INFO("Starting Ship of Harkinian version {}", (char*)gBuildVersion); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_Animation), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_PlayerAnimation), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_Room), std::make_shared()); // Is room scene? maybe? - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_CollisionHeader), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_Skeleton), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_SkeletonLimb), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_Path), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_Cutscene), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_Text), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_AudioSample), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_AudioSoundFont), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_AudioSequence), std::make_shared()); - context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast(LUS::ResourceType::SOH_Background), std::make_shared()); + auto loader = context->GetResourceManager()->GetResourceLoader(); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "SOH_Animation", static_cast(SohResourceType::SOH_Animation), 0); + + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_PlayerAnimation), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_Room), std::make_shared()); // Is room scene? maybe? + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_CollisionHeader), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_Skeleton), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_SkeletonLimb), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_Path), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_Cutscene), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_Text), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_AudioSample), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_AudioSoundFont), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_AudioSequence), std::make_shared()); + loader->RegisterResourceFactory(static_cast(SohResourceType::SOH_Background), std::make_shared()); gSaveStateMgr = std::make_shared(); gRandomizer = std::make_shared(); diff --git a/soh/soh/resource/importer/AnimationFactory.cpp b/soh/soh/resource/importer/AnimationFactory.cpp index c2aaf3067..4d7b79c53 100644 --- a/soh/soh/resource/importer/AnimationFactory.cpp +++ b/soh/soh/resource/importer/AnimationFactory.cpp @@ -2,103 +2,91 @@ #include "soh/resource/type/Animation.h" #include "spdlog/spdlog.h" -namespace LUS { -std::shared_ptr -AnimationFactory::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 Animation with version {}", resource->GetInitData()->ResourceVersion); +std::shared_ptr ResourceFactoryBinaryAnimationV0::ReadResource(std::shared_ptr file) { + if (file->InitData->Format != RESOURCE_FORMAT_BINARY) { + SPDLOG_ERROR("resource file format does not match factory format."); return nullptr; } - factory->ParseFileBinary(reader, resource); + if (file->Reader == nullptr) { + SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type, + file->InitData->Path); + return nullptr; + } - return resource; -} + auto animation = std::make_shared(file->InitData); -void LUS::AnimationFactoryV0::ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) { - std::shared_ptr animation = std::static_pointer_cast(resource); - - ResourceVersionFactory::ParseFileBinary(reader, animation); - - AnimationType animType = (AnimationType)reader->ReadUInt32(); + AnimationType animType = (AnimationType)file->Reader->ReadUInt32(); animation->type = animType; if (animType == AnimationType::Normal) { // Set frame count - animation->animationData.animationHeader.common.frameCount = reader->ReadInt16(); + animation->animationData.animationHeader.common.frameCount = file->Reader->ReadInt16(); // Populate frame data - uint32_t rotValuesCnt = reader->ReadUInt32(); + uint32_t rotValuesCnt = file->Reader->ReadUInt32(); animation->rotationValues.reserve(rotValuesCnt); for (uint32_t i = 0; i < rotValuesCnt; i++) { - animation->rotationValues.push_back(reader->ReadUInt16()); + animation->rotationValues.push_back(file->Reader->ReadUInt16()); } animation->animationData.animationHeader.frameData = (int16_t*)animation->rotationValues.data(); // Populate joint indices - uint32_t rotIndCnt = reader->ReadUInt32(); + uint32_t rotIndCnt = file->Reader->ReadUInt32(); animation->rotationIndices.reserve(rotIndCnt); for (size_t i = 0; i < rotIndCnt; i++) { - uint16_t x = reader->ReadUInt16(); - uint16_t y = reader->ReadUInt16(); - uint16_t z = reader->ReadUInt16(); + uint16_t x = file->Reader->ReadUInt16(); + uint16_t y = file->Reader->ReadUInt16(); + uint16_t z = file->Reader->ReadUInt16(); animation->rotationIndices.push_back(RotationIndex(x, y, z)); } animation->animationData.animationHeader.jointIndices = (JointIndex*)animation->rotationIndices.data(); // Set static index max - animation->animationData.animationHeader.staticIndexMax = reader->ReadInt16(); + animation->animationData.animationHeader.staticIndexMax = file->Reader->ReadInt16(); } else if (animType == AnimationType::Curve) { // Read frame count (unused in this animation type) - reader->ReadInt16(); + file->Reader->ReadInt16(); // Set refIndex - uint32_t refArrCnt = reader->ReadUInt32(); + uint32_t refArrCnt = file->Reader->ReadUInt32(); animation->refIndexArr.reserve(refArrCnt); for (uint32_t i = 0; i < refArrCnt; i++) { - animation->refIndexArr.push_back(reader->ReadUByte()); + animation->refIndexArr.push_back(file->Reader->ReadUByte()); } animation->animationData.transformUpdateIndex.refIndex = animation->refIndexArr.data(); // Populate transform data - uint32_t transformDataCnt = reader->ReadUInt32(); + uint32_t transformDataCnt = file->Reader->ReadUInt32(); animation->transformDataArr.reserve(transformDataCnt); for (uint32_t i = 0; i < transformDataCnt; i++) { TransformData data; - data.unk_00 = reader->ReadUInt16(); - data.unk_02 = reader->ReadInt16(); - data.unk_04 = reader->ReadInt16(); - data.unk_06 = reader->ReadInt16(); - data.unk_08 = reader->ReadFloat(); + data.unk_00 = file->Reader->ReadUInt16(); + data.unk_02 = file->Reader->ReadInt16(); + data.unk_04 = file->Reader->ReadInt16(); + data.unk_06 = file->Reader->ReadInt16(); + data.unk_08 = file->Reader->ReadFloat(); animation->transformDataArr.push_back(data); } animation->animationData.transformUpdateIndex.transformData = animation->transformDataArr.data(); // Populate copy values - uint32_t copyValuesCnt = reader->ReadUInt32(); + uint32_t copyValuesCnt = file->Reader->ReadUInt32(); animation->copyValuesArr.reserve(copyValuesCnt); for (uint32_t i = 0; i < copyValuesCnt; i++) { - animation->copyValuesArr.push_back(reader->ReadInt16()); + animation->copyValuesArr.push_back(file->Reader->ReadInt16()); } animation->animationData.transformUpdateIndex.copyValues = animation->copyValuesArr.data(); } else if (animType == AnimationType::Link) { // Read the frame count - animation->animationData.linkAnimationHeader.common.frameCount = reader->ReadInt16(); + animation->animationData.linkAnimationHeader.common.frameCount = file->Reader->ReadInt16(); // Read the segment pointer (always 32 bit, doesn't adjust for system pointer size) - animation->animationData.linkAnimationHeader.segment = (void*)reader->ReadUInt32(); + animation->animationData.linkAnimationHeader.segment = (void*)file->Reader->ReadUInt32(); } else if (animType == AnimationType::Legacy) { SPDLOG_DEBUG("BEYTAH ANIMATION?!"); } + + return animation; } -} // namespace LUS diff --git a/soh/soh/resource/importer/AnimationFactory.h b/soh/soh/resource/importer/AnimationFactory.h index dee2026f9..773c9fb92 100644 --- a/soh/soh/resource/importer/AnimationFactory.h +++ b/soh/soh/resource/importer/AnimationFactory.h @@ -3,15 +3,7 @@ #include "Resource.h" #include "ResourceFactory.h" -namespace LUS { -class AnimationFactory : public ResourceFactory { +class ResourceFactoryBinaryAnimationV0 : public LUS::ResourceFactory { public: - std::shared_ptr - ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; + std::shared_ptr ReadResource(std::shared_ptr file) override; }; - -class AnimationFactoryV0 : public ResourceVersionFactory { - public: - void ParseFileBinary(std::shared_ptr reader, std::shared_ptr resource) override; -}; -}; // namespace LUS diff --git a/soh/soh/resource/type/Animation.h b/soh/soh/resource/type/Animation.h index 3d6b810bf..4f20c2da3 100644 --- a/soh/soh/resource/type/Animation.h +++ b/soh/soh/resource/type/Animation.h @@ -3,85 +3,83 @@ #include "Resource.h" #include -namespace LUS { - enum class AnimationType { - Normal = 0, - Link = 1, - Curve = 2, - Legacy = 3, - }; +enum class AnimationType { + Normal = 0, + Link = 1, + Curve = 2, + Legacy = 3, +}; - struct RotationIndex { - uint16_t x, y, z; +struct RotationIndex { + uint16_t x, y, z; - RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) : x(nX), y(nY), z(nZ) { - } - }; + RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) : x(nX), y(nY), z(nZ) { + } +}; - typedef struct { - /* 0x0000 */ u16 unk_00; // appears to be flags - /* 0x0002 */ s16 unk_02; - /* 0x0004 */ s16 unk_04; - /* 0x0006 */ s16 unk_06; - /* 0x0008 */ f32 unk_08; - } TransformData; // size = 0xC +typedef struct { + /* 0x0000 */ u16 unk_00; // appears to be flags + /* 0x0002 */ s16 unk_02; + /* 0x0004 */ s16 unk_04; + /* 0x0006 */ s16 unk_06; + /* 0x0008 */ f32 unk_08; +} TransformData; // size = 0xC - typedef struct { - /* 0x0000 */ u8* refIndex; - /* 0x0004 */ TransformData* transformData; - /* 0x0008 */ s16* copyValues; - /* 0x000C */ s16 unk_0C; - /* 0x000E */ s16 unk_0E; - } TransformUpdateIndex; // size = 0x10 +typedef struct { + /* 0x0000 */ u8* refIndex; + /* 0x0004 */ TransformData* transformData; + /* 0x0008 */ s16* copyValues; + /* 0x000C */ s16 unk_0C; + /* 0x000E */ s16 unk_0E; +} TransformUpdateIndex; // size = 0x10 - typedef struct { - /* 0x00 */ s16 frameCount; - } AnimationHeaderCommon; +typedef struct { + /* 0x00 */ s16 frameCount; +} AnimationHeaderCommon; - // Index into the frame data table. - typedef struct { - /* 0x00 */ u16 x; - /* 0x02 */ u16 y; - /* 0x04 */ u16 z; - } JointIndex; // size = 0x06 +// Index into the frame data table. +typedef struct { + /* 0x00 */ u16 x; + /* 0x02 */ u16 y; + /* 0x04 */ u16 z; +} JointIndex; // size = 0x06 - typedef struct { - /* 0x00 */ AnimationHeaderCommon common; - /* 0x04 */ s16* frameData; // "tbl" - /* 0x08 */ JointIndex* jointIndices; // "ref_tbl" - /* 0x0C */ u16 staticIndexMax; - } AnimationHeader; // size = 0x10 +typedef struct { + /* 0x00 */ AnimationHeaderCommon common; + /* 0x04 */ s16* frameData; // "tbl" + /* 0x08 */ JointIndex* jointIndices; // "ref_tbl" + /* 0x0C */ u16 staticIndexMax; +} AnimationHeader; // size = 0x10 - typedef struct { - /* 0x00 */ AnimationHeaderCommon common; - /* 0x04 */ void* segment; - } LinkAnimationHeader; // size = 0x8 +typedef struct { + /* 0x00 */ AnimationHeaderCommon common; + /* 0x04 */ void* segment; +} LinkAnimationHeader; // size = 0x8 - union AnimationData { - AnimationHeader animationHeader; - LinkAnimationHeader linkAnimationHeader; - TransformUpdateIndex transformUpdateIndex; - }; +union AnimationData { +AnimationHeader animationHeader; +LinkAnimationHeader linkAnimationHeader; +TransformUpdateIndex transformUpdateIndex; +}; - class Animation : public Resource { - public: - using Resource::Resource; +class Animation : public LUS::Resource { +public: + using Resource::Resource; - Animation() : Resource(std::shared_ptr()) {} + Animation() : Resource(std::shared_ptr()) {} - AnimationData* GetPointer(); - size_t GetPointerSize(); + AnimationData* GetPointer(); + size_t GetPointerSize(); - AnimationType type; - AnimationData animationData; + AnimationType type; + AnimationData animationData; - // NORMAL - std::vector rotationValues; - std::vector rotationIndices; + // NORMAL + std::vector rotationValues; + std::vector rotationIndices; - // CURVE - std::vector refIndexArr; - std::vector transformDataArr; - std::vector copyValuesArr; - }; -}; // namespace LUS \ No newline at end of file + // CURVE + std::vector refIndexArr; + std::vector transformDataArr; + std::vector copyValuesArr; +}; diff --git a/soh/soh/resource/type/SohResourceType.h b/soh/soh/resource/type/SohResourceType.h new file mode 100644 index 000000000..89b32f594 --- /dev/null +++ b/soh/soh/resource/type/SohResourceType.h @@ -0,0 +1,19 @@ +#pragma once + +enum class SohResourceType { + SOH_Animation = 0x4F414E4D, // OANM + SOH_PlayerAnimation = 0x4F50414D, // OPAM + SOH_Room = 0x4F524F4D, // OROM + SOH_CollisionHeader = 0x4F434F4C, // OCOL + SOH_Skeleton = 0x4F534B4C, // OSKL + SOH_SkeletonLimb = 0x4F534C42, // OSLB + SOH_Path = 0x4F505448, // OPTH + SOH_Cutscene = 0x4F435654, // OCUT + SOH_Text = 0x4F545854, // OTXT + SOH_Audio = 0x4F415544, // OAUD + SOH_AudioSample = 0x4F534D50, // OSMP + SOH_AudioSoundFont = 0x4F534654, // OSFT + SOH_AudioSequence = 0x4F534551, // OSEQ + SOH_Background = 0x4F424749, // OBGI + SOH_SceneCommand = 0x4F52434D, // ORCM +};