diff options
| author | petrie911 <petrie911@yahoo.com> | 2024-04-25 14:02:54 -0500 |
|---|---|---|
| committer | Lywx <kiritodev01@gmail.com> | 2024-04-25 14:48:25 -0600 |
| commit | 48f1be277ccfbf3b4a867b831b0268304f9379d6 (patch) | |
| tree | b95b63b4c1d7ce08399290231b304af4fc238c40 | |
| parent | c7658c9d7f476bf68658c78ceb9f7610c629289b (diff) | |
env
| -rw-r--r-- | src/Companion.cpp | 4 | ||||
| -rw-r--r-- | src/factories/ResourceType.h | 2 | ||||
| -rw-r--r-- | src/factories/sf64/EnvSettingsFactory.cpp | 111 | ||||
| -rw-r--r-- | src/factories/sf64/EnvironmentFactory.cpp | 115 | ||||
| -rw-r--r-- | src/factories/sf64/EnvironmentFactory.h (renamed from src/factories/sf64/EnvSettingsFactory.h) | 22 |
5 files changed, 129 insertions, 125 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp index 9d8f3b1..97fedab 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -58,7 +58,7 @@ #include "factories/sf64/AnimFactory.h" #include "factories/sf64/ScriptFactory.h" #include "factories/sf64/HitboxFactory.h" -#include "factories/sf64/EnvSettingsFactory.h" +#include "factories/sf64/EnvironmentFactory.h" #include "factories/sf64/ObjInitFactory.h" #include "factories/sf64/TriangleFactory.h" @@ -124,7 +124,7 @@ void Companion::Init(const ExportType type) { this->RegisterFactory("SF64:MSG_TABLE", std::make_shared<SF64::MessageLookupFactory>()); this->RegisterFactory("SF64:SCRIPT", std::make_shared<SF64::ScriptFactory>()); this->RegisterFactory("SF64:HITBOX", std::make_shared<SF64::HitboxFactory>()); - this->RegisterFactory("SF64:ENV_SETTINGS", std::make_shared<SF64::EnvSettingsFactory>()); + this->RegisterFactory("SF64:ENVIRONMENT", std::make_shared<SF64::EnvironmentFactory>()); this->RegisterFactory("SF64:OBJECT_INIT", std::make_shared<SF64::ObjInitFactory>()); this->RegisterFactory("SF64:COLPOLY", std::make_shared<SF64::ColPolyFactory>()); this->RegisterFactory("SF64:TRIANGLE", std::make_shared<SF64::TriangleFactory>()); diff --git a/src/factories/ResourceType.h b/src/factories/ResourceType.h index 6ba4b1d..716a298 100644 --- a/src/factories/ResourceType.h +++ b/src/factories/ResourceType.h @@ -49,7 +49,7 @@ enum class ResourceType { // SF64 AnimData = 0x414E494D, // ANIM ColPoly = 0x43504C59, // CPLY - EnvSettings = 0x454E5653, // ENVS + Environment = 0x454E5653, // ENVS Limb = 0x4C494D42, // LIMB Message = 0x4D534720, // MSG MessageTable = 0x4D534754, // MSGT diff --git a/src/factories/sf64/EnvSettingsFactory.cpp b/src/factories/sf64/EnvSettingsFactory.cpp deleted file mode 100644 index bdf27f3..0000000 --- a/src/factories/sf64/EnvSettingsFactory.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "EnvSettingsFactory.h" -#include "spdlog/spdlog.h" - -#include "Companion.h" -#include "utils/Decompressor.h" -#include "utils/TorchUtils.h" - -SF64::EnvSettingsData::EnvSettingsData(int32_t type, int32_t unk_04, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, Vec3f unk_20, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB): mType(type), mUnk_04(unk_04), mBgColor(bgColor), mSeqId(seqId), mFogR(fogR), mFogG(fogG), mFogB(fogB), mFogN(fogN), mFogF(fogF), mUnk_20(unk_20), mLightR(lightR), mLightG(lightG), mLightB(lightB), mAmbR(ambR), mAmbG(ambG), mAmbB(ambB) { - -} - -ExportResult SF64::EnvSettingsHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { - const auto symbol = GetSafeNode(node, "symbol", entryName); - - if(Companion::Instance->IsOTRMode()){ - write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; - return std::nullopt; - } - - write << "extern EnvSettings " << symbol << ";\n"; - return std::nullopt; -} - -ExportResult SF64::EnvSettingsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { - const auto symbol = GetSafeNode(node, "symbol", entryName); - const auto offset = GetSafeNode<uint32_t>(node, "offset"); - auto env = std::static_pointer_cast<SF64::EnvSettingsData>(raw); - - write << "EnvSettings " << symbol << " = {\n"; - write << fourSpaceTab; - write << std::dec << env->mType << ", "; - write << env->mUnk_04 << ", "; - write << env->mBgColor << ", "; - if (env->mSeqId == 0xFFFF) { - write << "SEQ_ID_NONE, "; - } else { - auto seqId = Companion::Instance->GetEnumFromValue("BgmSeqIds", env->mSeqId & 0xFF).value_or("/* SEQ_ID_UNK */ " + std::to_string(env->mSeqId)); - write << seqId << ((env->mSeqId < 0x8000) ? "" : " | SEQ_FLAG") << ", "; - } - write << env->mFogR << ", "; - write << env->mFogG << ", "; - write << env->mFogB << ", "; - write << env->mFogN << ", "; - write << env->mFogF << ", "; - write << env->mUnk_20 << ", "; - write << env->mLightR << ", "; - write << env->mLightG << ", "; - write << env->mLightB << ", "; - write << env->mAmbR << ", "; - write << env->mAmbG << ", "; - write << env->mAmbB << ",\n"; - write << "};\n"; - - return offset + sizeof(EnvSettingsData); -} - -ExportResult SF64::EnvSettingsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { - auto writer = LUS::BinaryWriter(); - auto envSettings = std::static_pointer_cast<SF64::EnvSettingsData>(raw); - - WriteHeader(writer, LUS::ResourceType::EnvSettings, 0); - - writer.Write(envSettings->mType); - writer.Write(envSettings->mUnk_04); - writer.Write(envSettings->mBgColor); - writer.Write(envSettings->mSeqId); - writer.Write(envSettings->mFogR); - writer.Write(envSettings->mFogG); - writer.Write(envSettings->mFogB); - writer.Write(envSettings->mFogN); - writer.Write(envSettings->mFogF); - writer.Write(envSettings->mUnk_20.x); - writer.Write(envSettings->mUnk_20.y); - writer.Write(envSettings->mUnk_20.z); - writer.Write(envSettings->mLightR); - writer.Write(envSettings->mLightG); - writer.Write(envSettings->mLightB); - writer.Write(envSettings->mAmbR); - writer.Write(envSettings->mAmbG); - writer.Write(envSettings->mAmbB); - - writer.Finish(write); - return std::nullopt; -} - -std::optional<std::shared_ptr<IParsedData>> SF64::EnvSettingsFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { - auto [_, segment] = Decompressor::AutoDecode(node, buffer, sizeof(SF64::EnvSettingsData)); - LUS::BinaryReader reader(segment.data, segment.size); - reader.SetEndianness(LUS::Endianness::Big); - Vec3f unk_20; - int32_t type = reader.ReadInt32(); - int32_t unk_04 = reader.ReadInt32(); - uint16_t bgColor = reader.ReadUInt16(); - uint16_t seqId = reader.ReadUInt16(); - int32_t fogR = reader.ReadInt32(); - int32_t fogG = reader.ReadInt32(); - int32_t fogB = reader.ReadInt32(); - int32_t fogN = reader.ReadInt32(); - int32_t fogF = reader.ReadInt32(); - unk_20.x = reader.ReadFloat(); - unk_20.y = reader.ReadFloat(); - unk_20.z = reader.ReadFloat(); - int32_t lightR = reader.ReadInt32(); - int32_t lightG = reader.ReadInt32(); - int32_t lightB = reader.ReadInt32(); - int32_t ambR = reader.ReadInt32(); - int32_t ambG = reader.ReadInt32(); - int32_t ambB = reader.ReadInt32(); - - return std::make_shared<SF64::EnvSettingsData>(type, unk_04, bgColor, seqId, fogR, fogG, fogB, fogN, fogF, unk_20, lightR, lightG, lightB, ambR, ambG, ambB); -} diff --git a/src/factories/sf64/EnvironmentFactory.cpp b/src/factories/sf64/EnvironmentFactory.cpp new file mode 100644 index 0000000..14d3e2b --- /dev/null +++ b/src/factories/sf64/EnvironmentFactory.cpp @@ -0,0 +1,115 @@ +#include "EnvironmentFactory.h" +#include "spdlog/spdlog.h" + +#include "Companion.h" +#include "utils/Decompressor.h" +#include "utils/TorchUtils.h" + +#define VALUE_TO_ENUM(val, enumname, fallback) (Companion::Instance->GetEnumFromValue(enumname, val).value_or("/*" + std::string(fallback) + " */ " + std::to_string(val))); + +SF64::EnvironmentData::EnvironmentData(int32_t type, int32_t ground, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, Vec3f lightDir, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB): mType(type), mGround(ground), mBgColor(bgColor), mSeqId(seqId), mFogR(fogR), mFogG(fogG), mFogB(fogB), mFogN(fogN), mFogF(fogF), mLightDir(lightDir), mLightR(lightR), mLightG(lightG), mLightB(lightB), mAmbR(ambR), mAmbG(ambG), mAmbB(ambB) { + +} + +ExportResult SF64::EnvironmentHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) { + const auto symbol = GetSafeNode(node, "symbol", entryName); + + if(Companion::Instance->IsOTRMode()){ + write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; + return std::nullopt; + } + + write << "extern Environment " << symbol << ";\n"; + return std::nullopt; +} + +ExportResult SF64::EnvironmentCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + const auto symbol = GetSafeNode(node, "symbol", entryName); + const auto offset = GetSafeNode<uint32_t>(node, "offset"); + auto env = std::static_pointer_cast<SF64::EnvironmentData>(raw); + + write << "Environment " << symbol << " = {\n"; + write << fourSpaceTab; + auto type = VALUE_TO_ENUM(env->mType, "LevelType", "LEVELTYPE_UNK"); + write << type << ", "; + auto ground = VALUE_TO_ENUM(env->mGround, "GroundType", "GROUND_UNK"); + write << ground << ", "; + write << "0x" << std::hex << std::uppercase << env->mBgColor << ", "; + if (env->mSeqId == 0xFFFF) { + write << "SEQ_ID_NONE, "; + } else { + auto seqId = Companion::Instance->GetEnumFromValue("BgmSeqIds", env->mSeqId & 0xFF).value_or("/* SEQ_ID_UNK */ " + std::to_string(env->mSeqId)); + write << seqId << ((env->mSeqId < 0x8000) ? "" : " | SEQ_FLAG") << ", "; + } + write << std::dec << env->mFogR << ", "; + write << env->mFogG << ", "; + write << env->mFogB << ", "; + write << env->mFogN << ", "; + write << env->mFogF << ", "; + write << env->mLightDir << ", "; + write << env->mLightR << ", "; + write << env->mLightG << ", "; + write << env->mLightB << ", "; + write << env->mAmbR << ", "; + write << env->mAmbG << ", "; + write << env->mAmbB << ",\n"; + write << "};\n"; + + return offset + sizeof(EnvironmentData); +} + +ExportResult SF64::EnvironmentBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + auto writer = LUS::BinaryWriter(); + auto environment = std::static_pointer_cast<SF64::EnvironmentData>(raw); + + WriteHeader(writer, LUS::ResourceType::Environment, 0); + + writer.Write(environment->mType); + writer.Write(environment->mGround); + writer.Write(environment->mBgColor); + writer.Write(environment->mSeqId); + writer.Write(environment->mFogR); + writer.Write(environment->mFogG); + writer.Write(environment->mFogB); + writer.Write(environment->mFogN); + writer.Write(environment->mFogF); + writer.Write(environment->mLightDir.x); + writer.Write(environment->mLightDir.y); + writer.Write(environment->mLightDir.z); + writer.Write(environment->mLightR); + writer.Write(environment->mLightG); + writer.Write(environment->mLightB); + writer.Write(environment->mAmbR); + writer.Write(environment->mAmbG); + writer.Write(environment->mAmbB); + + writer.Finish(write); + return std::nullopt; +} + +std::optional<std::shared_ptr<IParsedData>> SF64::EnvironmentFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { + auto [_, segment] = Decompressor::AutoDecode(node, buffer, sizeof(SF64::EnvironmentData)); + LUS::BinaryReader reader(segment.data, segment.size); + reader.SetEndianness(LUS::Endianness::Big); + Vec3f lightDir; + int32_t type = reader.ReadInt32(); + int32_t ground = reader.ReadInt32(); + uint16_t bgColor = reader.ReadUInt16(); + uint16_t seqId = reader.ReadUInt16(); + int32_t fogR = reader.ReadInt32(); + int32_t fogG = reader.ReadInt32(); + int32_t fogB = reader.ReadInt32(); + int32_t fogN = reader.ReadInt32(); + int32_t fogF = reader.ReadInt32(); + lightDir.x = reader.ReadFloat(); + lightDir.y = reader.ReadFloat(); + lightDir.z = reader.ReadFloat(); + int32_t lightR = reader.ReadInt32(); + int32_t lightG = reader.ReadInt32(); + int32_t lightB = reader.ReadInt32(); + int32_t ambR = reader.ReadInt32(); + int32_t ambG = reader.ReadInt32(); + int32_t ambB = reader.ReadInt32(); + + return std::make_shared<SF64::EnvironmentData>(type, ground, bgColor, seqId, fogR, fogG, fogB, fogN, fogF, lightDir, lightR, lightG, lightB, ambR, ambG, ambB); +} diff --git a/src/factories/sf64/EnvSettingsFactory.h b/src/factories/sf64/EnvironmentFactory.h index 156886e..a184113 100644 --- a/src/factories/sf64/EnvSettingsFactory.h +++ b/src/factories/sf64/EnvironmentFactory.h @@ -5,10 +5,10 @@ namespace SF64 { -class EnvSettingsData : public IParsedData { +class EnvironmentData : public IParsedData { public: int32_t mType; - int32_t mUnk_04; + int32_t mGround; uint16_t mBgColor; uint16_t mSeqId; int32_t mFogR; @@ -16,7 +16,7 @@ public: int32_t mFogB; int32_t mFogN; int32_t mFogF; - Vec3f mUnk_20; + Vec3f mLightDir; int32_t mLightR; int32_t mLightG; int32_t mLightB; @@ -24,29 +24,29 @@ public: int32_t mAmbG; int32_t mAmbB; - EnvSettingsData(int32_t type, int32_t unk_04, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, Vec3f unk_20, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB); + EnvironmentData(int32_t type, int32_t ground, uint16_t bgColor, uint16_t seqId, int32_t fogR, int32_t fogG, int32_t fogB, int32_t fogN, int32_t fogF, Vec3f lightDir, int32_t lightR, int32_t lightG, int32_t lightB, int32_t ambR, int32_t ambG, int32_t ambB); }; -class EnvSettingsHeaderExporter : public BaseExporter { +class EnvironmentHeaderExporter : public BaseExporter { ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; -class EnvSettingsBinaryExporter : public BaseExporter { +class EnvironmentBinaryExporter : public BaseExporter { ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; -class EnvSettingsCodeExporter : public BaseExporter { +class EnvironmentCodeExporter : public BaseExporter { ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override; }; -class EnvSettingsFactory : public BaseFactory { +class EnvironmentFactory : public BaseFactory { public: std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override; inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override { return { - REGISTER(Code, EnvSettingsCodeExporter) - REGISTER(Header, EnvSettingsHeaderExporter) - REGISTER(Binary, EnvSettingsBinaryExporter) + REGISTER(Code, EnvironmentCodeExporter) + REGISTER(Header, EnvironmentHeaderExporter) + REGISTER(Binary, EnvironmentBinaryExporter) }; } }; |
