diff --git a/DataSpec/DNACommon/DNACommon.hpp b/DataSpec/DNACommon/DNACommon.hpp index 127db2c33..e3c493291 100644 --- a/DataSpec/DNACommon/DNACommon.hpp +++ b/DataSpec/DNACommon/DNACommon.hpp @@ -31,7 +31,7 @@ class UniqueID32 : public BigDNA public: Delete expl; inline void read(Athena::io::IStreamReader& reader) - {reader.readUint32();} + {m_id = reader.readUint32();} inline void write(Athena::io::IStreamWriter& writer) const {writer.writeUint32(m_id);} @@ -53,7 +53,7 @@ class UniqueID64 : public BigDNA public: Delete expl; inline void read(Athena::io::IStreamReader& reader) - {reader.readUint64();} + {m_id = reader.readUint64();} inline void write(Athena::io::IStreamWriter& writer) const {writer.writeUint64(m_id);} diff --git a/DataSpec/DNAMP1/MLVL.hpp b/DataSpec/DNAMP1/MLVL.hpp index 38c716af2..457c540a0 100644 --- a/DataSpec/DNAMP1/MLVL.hpp +++ b/DataSpec/DNAMP1/MLVL.hpp @@ -45,7 +45,7 @@ struct MLVL : BigDNA { DECL_DNA UniqueID32 id; - HECL::FourCC type; + FourCC type; }; Vector deps; @@ -63,7 +63,6 @@ struct MLVL : BigDNA Value areaIdx; Value dockIdx; }; - HECL::FourCC type; Vector endpoints; Value planeVertCount; @@ -71,6 +70,7 @@ struct MLVL : BigDNA }; Vector docks; }; + Vector areas; UniqueID32 worldMap; Value unknown2; diff --git a/DataSpec/DNAMP1/PAK.cpp b/DataSpec/DNAMP1/PAK.cpp index a8394fffc..686a08e8a 100644 --- a/DataSpec/DNAMP1/PAK.cpp +++ b/DataSpec/DNAMP1/PAK.cpp @@ -34,6 +34,12 @@ void PAK::read(Athena::io::IStreamReader& reader) m_idMap[m_entries.back().id] = &m_entries.back(); } + atUint32 realCount = 0; + for (Entry& entry : m_entries) + { + ++realCount; + } + m_nameMap.clear(); m_nameMap.reserve(nameCount); for (NameEntry& entry : m_nameEntries) diff --git a/DataSpec/DNAMP1/PAK.hpp b/DataSpec/DNAMP1/PAK.hpp index 94c80cd71..0fd223905 100644 --- a/DataSpec/DNAMP1/PAK.hpp +++ b/DataSpec/DNAMP1/PAK.hpp @@ -14,6 +14,8 @@ namespace DNAMP1 class PAK : public BigDNA { public: + DECL_EXPLICIT_DNA + struct NameEntry : public BigDNA { DECL_DNA @@ -33,15 +35,11 @@ public: Value offset; }; -private: std::vector m_nameEntries; std::vector m_entries; std::unordered_map m_idMap; std::unordered_map m_nameMap; -public: - DECL_EXPLICIT_DNA - inline const Entry* lookupEntry(const UniqueID32& id) const { std::unordered_map::const_iterator result = m_idMap.find(id); @@ -57,9 +55,6 @@ public: return result->second; return nullptr; } - - inline std::vector::iterator begin() {return m_entries.begin();} - inline std::vector::iterator end() {return m_entries.end();} }; } diff --git a/DataSpec/DNAMP1/STRG.cpp b/DataSpec/DNAMP1/STRG.cpp index b6ec8be4d..9f9baa7b6 100644 --- a/DataSpec/DNAMP1/STRG.cpp +++ b/DataSpec/DNAMP1/STRG.cpp @@ -15,6 +15,7 @@ const HECL::FourCC JAPNfcc("JAPN"); void STRG::read(Athena::io::IStreamReader& reader) { + reader.setEndian(Athena::BigEndian); uint32_t magic = reader.readUint32(); if (magic != 0x87654321) LogModule.report(LogVisor::FatalError, "invalid STRG magic"); @@ -46,6 +47,7 @@ void STRG::read(Athena::io::IStreamReader& reader) void STRG::write(Athena::io::IStreamWriter& writer) const { + writer.setEndian(Athena::BigEndian); writer.writeUint32(0x87654321); writer.writeUint32(version); writer.writeUint32(langs.size()); diff --git a/DataSpec/SpecMP1.cpp b/DataSpec/SpecMP1.cpp index a663e3aa1..3538c1577 100644 --- a/DataSpec/SpecMP1.cpp +++ b/DataSpec/SpecMP1.cpp @@ -11,7 +11,13 @@ namespace Retro struct SpecMP1 : SpecBase { - std::vector> m_paks; + struct DiscPAK + { + const NOD::DiscBase::IPartition::Node& node; + DNAMP1::PAK pak; + DiscPAK(const NOD::DiscBase::IPartition::Node& n) : node(n) {} + }; + std::vector m_paks; bool checkFromGCNDisc(NOD::DiscGCN& disc, const std::vector& args, @@ -40,7 +46,7 @@ struct SpecMP1 : SpecBase NOD::DiscGCN::IPartition* partition = disc.getDataPartition(); std::unique_ptr dolBuf = partition->getDOLBuf(); - const char* buildInfo = (char*)memmem(dolBuf.get(), partition->getDOLSize(), "MetroidBuildInfo", 16) + 16; + const char* buildInfo = (char*)memmem(dolBuf.get(), partition->getDOLSize(), "MetroidBuildInfo", 16) + 19; reps.emplace_back(); ExtractReport& rep = reps.back(); @@ -50,8 +56,6 @@ struct SpecMP1 : SpecBase rep.desc += " (" + std::string(buildInfo) + ")"; /* Iterate PAKs and build level options */ - std::map, - CaseInsensitiveCompare> orderedPaks; NOD::DiscBase::IPartition::Node& root = disc.getDataPartition()->getFSTRoot(); for (const NOD::DiscBase::IPartition::Node& child : root) { @@ -100,35 +104,39 @@ struct SpecMP1 : SpecBase if (good) { - m_paks.emplace_back(std::make_pair(name, DNAMP1::PAK())); - std::pair& res = m_paks.back(); + m_paks.emplace_back(child); NOD::AthenaPartReadStream rs(child.beginReadStream()); - res.second.read(rs); - orderedPaks[name] = std::make_pair(&child, &res.second); + m_paks.back().pak.read(rs); } } } } - for (std::pair> item : orderedPaks) + /* Sort PAKs alphabetically */ + std::map orderedPaks; + for (DiscPAK& dpak : m_paks) + orderedPaks[dpak.node.getName()] = &dpak; + + for (std::pair item : orderedPaks) { rep.childOpts.emplace_back(); ExtractReport& childRep = rep.childOpts.back(); childRep.name = item.first; - for (DNAMP1::PAK::Entry& entry : *item.second.second) + DNAMP1::PAK& pak = item.second->pak; + for (DNAMP1::PAK::Entry& entry : pak.m_entries) { static const HECL::FourCC MLVLfourcc("MLVL"); if (entry.type == MLVLfourcc) { - NOD::AthenaPartReadStream rs(item.second.first->beginReadStream(entry.offset)); + NOD::AthenaPartReadStream rs(item.second->node.beginReadStream(entry.offset)); DNAMP1::MLVL mlvl; mlvl.read(rs); - const DNAMP1::PAK::Entry* nameEnt = item.second.second->lookupEntry(mlvl.worldNameId); + const DNAMP1::PAK::Entry* nameEnt = pak.lookupEntry(mlvl.worldNameId); if (nameEnt) { DNAMP1::STRG mlvlName; - rs.seek(nameEnt->offset, Athena::Begin); + NOD::AthenaPartReadStream rs(item.second->node.beginReadStream(nameEnt->offset)); mlvlName.read(rs); if (childRep.desc.size()) childRep.desc += _S(", "); diff --git a/DataSpec/SpecMP2.cpp b/DataSpec/SpecMP2.cpp index f17c1db50..991bcd01d 100644 --- a/DataSpec/SpecMP2.cpp +++ b/DataSpec/SpecMP2.cpp @@ -4,5 +4,5 @@ static HECL::Database::DataSpecEntry SpecMP2 ( _S("MP2"), _S("Data specification for original Metroid Prime 2 engine"), - [](HECL::Database::DataSpecTool tool) -> HECL::Database::IDataSpec* {} + [](HECL::Database::DataSpecTool tool) -> HECL::Database::IDataSpec* {return nullptr;} ); diff --git a/DataSpec/SpecMP3.cpp b/DataSpec/SpecMP3.cpp index 754385817..5bf8199ed 100644 --- a/DataSpec/SpecMP3.cpp +++ b/DataSpec/SpecMP3.cpp @@ -4,6 +4,6 @@ static HECL::Database::DataSpecEntry SpecMP3 ( _S("MP3"), _S("Data specification for original Metroid Prime 3 engine"), - [](HECL::Database::DataSpecTool tool) -> HECL::Database::IDataSpec* {} + [](HECL::Database::DataSpecTool tool) -> HECL::Database::IDataSpec* {return nullptr;} );