diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 04601922..03c24033 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -4,9 +4,14 @@ #include "libultraship/src/Context.h" #include "resource/type/ResourceType.h" #include "resource/importers/AnimFactory.h" +#include "resource/importers/EnvSettingsFactory.h" +#include "resource/importers/HitboxFactory.h" #include "resource/importers/LimbFactory.h" #include "resource/importers/MessageFactory.h" #include "resource/importers/MessageLookupFactory.h" +#include "resource/importers/ObjectInitFactory.h" +#include "resource/importers/ScriptCommandFactory.h" +#include "resource/importers/ScriptFactory.h" #include "resource/importers/SkeletonFactory.h" #include @@ -48,7 +53,12 @@ GameEngine::GameEngine() { loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Skeleton", static_cast(SF64::ResourceType::Skeleton), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Limb", static_cast(SF64::ResourceType::Limb), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Message", static_cast(SF64::ResourceType::Message), 0); - loader->RegisterResourceFactory( std::make_shared(), RESOURCE_FORMAT_BINARY, "MessageTable", static_cast(SF64::ResourceType::MessageTable), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "MessageTable", static_cast(SF64::ResourceType::MessageTable), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "EnvSettings", static_cast(SF64::ResourceType::EnvSettings), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "ObjectInit", static_cast(SF64::ResourceType::ObjectInit), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Hitbox", static_cast(SF64::ResourceType::Hitbox), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Script", static_cast(SF64::ResourceType::Script), 0); + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "ScriptCMD", static_cast(SF64::ResourceType::ScriptCmd), 0); } void GameEngine::Create(){ diff --git a/src/port/Engine.h b/src/port/Engine.h index fc531d4b..489b3a11 100644 --- a/src/port/Engine.h +++ b/src/port/Engine.h @@ -1,6 +1,6 @@ #pragma once -#define LOAD_ASSET(path) (GameEngine_OTRSigCheck((const char*) path) ? ResourceGetDataByName((const char*) path) : path) +#define LOAD_ASSET(path) (path == NULL ? NULL : (GameEngine_OTRSigCheck((const char*) path) ? ResourceGetDataByName((const char*) path) : path)) #define LOAD_ASSET_RAW(path) ResourceGetDataByName((const char*) path) #ifdef __cplusplus diff --git a/src/port/resource/importers/EnvSettingsFactory.cpp b/src/port/resource/importers/EnvSettingsFactory.cpp new file mode 100644 index 00000000..2822786b --- /dev/null +++ b/src/port/resource/importers/EnvSettingsFactory.cpp @@ -0,0 +1,38 @@ +#include "EnvSettingsFactory.h" + +#include "Context.h" +#include "resourcebridge.h" +#include "../type/EnvSettings.h" + +namespace SF64 { + +std::shared_ptr ResourceFactoryBinaryEnvSettingsV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto env = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + env->mSettings.type = reader->ReadInt32(); + env->mSettings.unk_04 = reader->ReadInt32(); + env->mSettings.bgColor = reader->ReadUInt16(); + env->mSettings.seqId = reader->ReadUInt16(); + env->mSettings.fogR = reader->ReadInt32(); + env->mSettings.fogG = reader->ReadInt32(); + env->mSettings.fogB = reader->ReadInt32(); + env->mSettings.fogN = reader->ReadInt32(); + env->mSettings.fogF = reader->ReadInt32(); + env->mSettings.unk_20.x = reader->ReadFloat(); + env->mSettings.unk_20.y = reader->ReadFloat(); + env->mSettings.unk_20.z = reader->ReadFloat(); + env->mSettings.lightR = reader->ReadInt32(); + env->mSettings.lightG = reader->ReadInt32(); + env->mSettings.lightB = reader->ReadInt32(); + env->mSettings.ambR = reader->ReadInt32(); + env->mSettings.ambG = reader->ReadInt32(); + env->mSettings.ambB = reader->ReadInt32(); + + return env; +} +} // namespace LUS diff --git a/src/port/resource/importers/EnvSettingsFactory.h b/src/port/resource/importers/EnvSettingsFactory.h new file mode 100644 index 00000000..0ab76ff9 --- /dev/null +++ b/src/port/resource/importers/EnvSettingsFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryEnvSettingsV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/HitboxFactory.cpp b/src/port/resource/importers/HitboxFactory.cpp new file mode 100644 index 00000000..258c4049 --- /dev/null +++ b/src/port/resource/importers/HitboxFactory.cpp @@ -0,0 +1,22 @@ +#include "HitboxFactory.h" +#include "../type/Hitbox.h" +#include "spdlog/spdlog.h" + +namespace SF64 { +std::shared_ptr ResourceFactoryBinaryHitboxV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto hitbox = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + auto count = reader->ReadUInt32(); + + for (uint32_t i = 0; i < count; i++) { + hitbox->mHitbox.push_back(reader->ReadFloat()); + } + + return hitbox; +} +} // namespace LUS diff --git a/src/port/resource/importers/HitboxFactory.h b/src/port/resource/importers/HitboxFactory.h new file mode 100644 index 00000000..3b5fd64e --- /dev/null +++ b/src/port/resource/importers/HitboxFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryHitboxV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/ObjectInitFactory.cpp b/src/port/resource/importers/ObjectInitFactory.cpp new file mode 100644 index 00000000..9a7a3116 --- /dev/null +++ b/src/port/resource/importers/ObjectInitFactory.cpp @@ -0,0 +1,33 @@ +#include "ObjectInitFactory.h" + +#include "Context.h" +#include "resourcebridge.h" +#include "../type/ObjectInit.h" + +namespace SF64 { + +std::shared_ptr ResourceFactoryBinaryObjectInitV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto obj = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + auto count = reader->ReadUInt32(); + + for(size_t i = 0; i < count; i++) { + ObjectInitData data; + data.zPos1 = reader->ReadFloat(); + data.zPos2 = reader->ReadInt16(); + data.xPos = reader->ReadInt16(); + data.yPos = reader->ReadInt16(); + data.rot.x = reader->ReadInt16(); + data.rot.y = reader->ReadInt16(); + data.rot.z = reader->ReadInt16(); + data.id = reader->ReadInt16(); + obj->mObjects.push_back(data); + } + + return obj; +} +} // namespace LUS diff --git a/src/port/resource/importers/ObjectInitFactory.h b/src/port/resource/importers/ObjectInitFactory.h new file mode 100644 index 00000000..99297edd --- /dev/null +++ b/src/port/resource/importers/ObjectInitFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryObjectInitV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/ScriptCommandFactory.cpp b/src/port/resource/importers/ScriptCommandFactory.cpp new file mode 100644 index 00000000..3fcef793 --- /dev/null +++ b/src/port/resource/importers/ScriptCommandFactory.cpp @@ -0,0 +1,23 @@ +#include "ScriptCommandFactory.h" +#include "../type/Script.h" +#include "spdlog/spdlog.h" +#include "ResourceUtil.h" + +namespace SF64 { +std::shared_ptr ResourceFactoryBinaryScriptCMDV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto cmds = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + auto size = reader->ReadUInt32(); + + for (uint32_t i = 0; i < size * 2; i++) { + cmds->mCommands.push_back(reader->ReadUInt16()); + } + + return cmds; +} +} // namespace LUS diff --git a/src/port/resource/importers/ScriptCommandFactory.h b/src/port/resource/importers/ScriptCommandFactory.h new file mode 100644 index 00000000..6f119f73 --- /dev/null +++ b/src/port/resource/importers/ScriptCommandFactory.h @@ -0,0 +1,11 @@ +#pragma once + +#include "Resource.h" +#include "ResourceFactoryBinary.h" + +namespace SF64 { +class ResourceFactoryBinaryScriptCMDV0 : public LUS::ResourceFactoryBinary { + public: + std::shared_ptr ReadResource(std::shared_ptr file) override; +}; +}; // namespace LUS diff --git a/src/port/resource/importers/ScriptFactory.cpp b/src/port/resource/importers/ScriptFactory.cpp new file mode 100644 index 00000000..67503fcc --- /dev/null +++ b/src/port/resource/importers/ScriptFactory.cpp @@ -0,0 +1,23 @@ +#include "ScriptFactory.h" +#include "../type/Script.h" +#include "spdlog/spdlog.h" +#include "ResourceUtil.h" + +namespace SF64 { +std::shared_ptr ResourceFactoryBinaryScriptV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto script = std::make_shared