bug fixes with MP1's spec

This commit is contained in:
Jack Andersen 2015-07-11 18:26:26 -10:00
parent c1f4f31e6f
commit 975429f3c6
8 changed files with 37 additions and 26 deletions

View File

@ -31,7 +31,7 @@ class UniqueID32 : public BigDNA
public: public:
Delete expl; Delete expl;
inline void read(Athena::io::IStreamReader& reader) inline void read(Athena::io::IStreamReader& reader)
{reader.readUint32();} {m_id = reader.readUint32();}
inline void write(Athena::io::IStreamWriter& writer) const inline void write(Athena::io::IStreamWriter& writer) const
{writer.writeUint32(m_id);} {writer.writeUint32(m_id);}
@ -53,7 +53,7 @@ class UniqueID64 : public BigDNA
public: public:
Delete expl; Delete expl;
inline void read(Athena::io::IStreamReader& reader) inline void read(Athena::io::IStreamReader& reader)
{reader.readUint64();} {m_id = reader.readUint64();}
inline void write(Athena::io::IStreamWriter& writer) const inline void write(Athena::io::IStreamWriter& writer) const
{writer.writeUint64(m_id);} {writer.writeUint64(m_id);}

View File

@ -45,7 +45,7 @@ struct MLVL : BigDNA
{ {
DECL_DNA DECL_DNA
UniqueID32 id; UniqueID32 id;
HECL::FourCC type; FourCC type;
}; };
Vector<Dependency, DNA_COUNT(depCount)> deps; Vector<Dependency, DNA_COUNT(depCount)> deps;
@ -63,7 +63,6 @@ struct MLVL : BigDNA
Value<atUint32> areaIdx; Value<atUint32> areaIdx;
Value<atUint32> dockIdx; Value<atUint32> dockIdx;
}; };
HECL::FourCC type;
Vector<Endpoint, DNA_COUNT(endpointCount)> endpoints; Vector<Endpoint, DNA_COUNT(endpointCount)> endpoints;
Value<atUint32> planeVertCount; Value<atUint32> planeVertCount;
@ -71,6 +70,7 @@ struct MLVL : BigDNA
}; };
Vector<Dock, DNA_COUNT(dockCount)> docks; Vector<Dock, DNA_COUNT(dockCount)> docks;
}; };
Vector<Area, DNA_COUNT(areaCount)> areas;
UniqueID32 worldMap; UniqueID32 worldMap;
Value<atUint8> unknown2; Value<atUint8> unknown2;

View File

@ -34,6 +34,12 @@ void PAK::read(Athena::io::IStreamReader& reader)
m_idMap[m_entries.back().id] = &m_entries.back(); m_idMap[m_entries.back().id] = &m_entries.back();
} }
atUint32 realCount = 0;
for (Entry& entry : m_entries)
{
++realCount;
}
m_nameMap.clear(); m_nameMap.clear();
m_nameMap.reserve(nameCount); m_nameMap.reserve(nameCount);
for (NameEntry& entry : m_nameEntries) for (NameEntry& entry : m_nameEntries)

View File

@ -14,6 +14,8 @@ namespace DNAMP1
class PAK : public BigDNA class PAK : public BigDNA
{ {
public: public:
DECL_EXPLICIT_DNA
struct NameEntry : public BigDNA struct NameEntry : public BigDNA
{ {
DECL_DNA DECL_DNA
@ -33,15 +35,11 @@ public:
Value<atUint32> offset; Value<atUint32> offset;
}; };
private:
std::vector<NameEntry> m_nameEntries; std::vector<NameEntry> m_nameEntries;
std::vector<Entry> m_entries; std::vector<Entry> m_entries;
std::unordered_map<UniqueID32, Entry*> m_idMap; std::unordered_map<UniqueID32, Entry*> m_idMap;
std::unordered_map<std::string, Entry*> m_nameMap; std::unordered_map<std::string, Entry*> m_nameMap;
public:
DECL_EXPLICIT_DNA
inline const Entry* lookupEntry(const UniqueID32& id) const inline const Entry* lookupEntry(const UniqueID32& id) const
{ {
std::unordered_map<UniqueID32, Entry*>::const_iterator result = m_idMap.find(id); std::unordered_map<UniqueID32, Entry*>::const_iterator result = m_idMap.find(id);
@ -57,9 +55,6 @@ public:
return result->second; return result->second;
return nullptr; return nullptr;
} }
inline std::vector<Entry>::iterator begin() {return m_entries.begin();}
inline std::vector<Entry>::iterator end() {return m_entries.end();}
}; };
} }

View File

@ -15,6 +15,7 @@ const HECL::FourCC JAPNfcc("JAPN");
void STRG::read(Athena::io::IStreamReader& reader) void STRG::read(Athena::io::IStreamReader& reader)
{ {
reader.setEndian(Athena::BigEndian);
uint32_t magic = reader.readUint32(); uint32_t magic = reader.readUint32();
if (magic != 0x87654321) if (magic != 0x87654321)
LogModule.report(LogVisor::FatalError, "invalid STRG magic"); 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 void STRG::write(Athena::io::IStreamWriter& writer) const
{ {
writer.setEndian(Athena::BigEndian);
writer.writeUint32(0x87654321); writer.writeUint32(0x87654321);
writer.writeUint32(version); writer.writeUint32(version);
writer.writeUint32(langs.size()); writer.writeUint32(langs.size());

View File

@ -11,7 +11,13 @@ namespace Retro
struct SpecMP1 : SpecBase struct SpecMP1 : SpecBase
{ {
std::vector<std::pair<std::string, DNAMP1::PAK>> m_paks; struct DiscPAK
{
const NOD::DiscBase::IPartition::Node& node;
DNAMP1::PAK pak;
DiscPAK(const NOD::DiscBase::IPartition::Node& n) : node(n) {}
};
std::vector<DiscPAK> m_paks;
bool checkFromGCNDisc(NOD::DiscGCN& disc, bool checkFromGCNDisc(NOD::DiscGCN& disc,
const std::vector<const HECL::SystemString*>& args, const std::vector<const HECL::SystemString*>& args,
@ -40,7 +46,7 @@ struct SpecMP1 : SpecBase
NOD::DiscGCN::IPartition* partition = disc.getDataPartition(); NOD::DiscGCN::IPartition* partition = disc.getDataPartition();
std::unique_ptr<uint8_t[]> dolBuf = partition->getDOLBuf(); std::unique_ptr<uint8_t[]> 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(); reps.emplace_back();
ExtractReport& rep = reps.back(); ExtractReport& rep = reps.back();
@ -50,8 +56,6 @@ struct SpecMP1 : SpecBase
rep.desc += " (" + std::string(buildInfo) + ")"; rep.desc += " (" + std::string(buildInfo) + ")";
/* Iterate PAKs and build level options */ /* Iterate PAKs and build level options */
std::map<std::string, std::pair<const NOD::DiscBase::IPartition::Node*, DNAMP1::PAK*>,
CaseInsensitiveCompare> orderedPaks;
NOD::DiscBase::IPartition::Node& root = disc.getDataPartition()->getFSTRoot(); NOD::DiscBase::IPartition::Node& root = disc.getDataPartition()->getFSTRoot();
for (const NOD::DiscBase::IPartition::Node& child : root) for (const NOD::DiscBase::IPartition::Node& child : root)
{ {
@ -100,35 +104,39 @@ struct SpecMP1 : SpecBase
if (good) if (good)
{ {
m_paks.emplace_back(std::make_pair(name, DNAMP1::PAK())); m_paks.emplace_back(child);
std::pair<std::string, DNAMP1::PAK>& res = m_paks.back();
NOD::AthenaPartReadStream rs(child.beginReadStream()); NOD::AthenaPartReadStream rs(child.beginReadStream());
res.second.read(rs); m_paks.back().pak.read(rs);
orderedPaks[name] = std::make_pair(&child, &res.second);
} }
} }
} }
} }
for (std::pair<std::string, std::pair<const NOD::DiscBase::IPartition::Node*, DNAMP1::PAK*>> item : orderedPaks) /* Sort PAKs alphabetically */
std::map<std::string, DiscPAK*, CaseInsensitiveCompare> orderedPaks;
for (DiscPAK& dpak : m_paks)
orderedPaks[dpak.node.getName()] = &dpak;
for (std::pair<std::string, DiscPAK*> item : orderedPaks)
{ {
rep.childOpts.emplace_back(); rep.childOpts.emplace_back();
ExtractReport& childRep = rep.childOpts.back(); ExtractReport& childRep = rep.childOpts.back();
childRep.name = item.first; 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"); static const HECL::FourCC MLVLfourcc("MLVL");
if (entry.type == MLVLfourcc) 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; DNAMP1::MLVL mlvl;
mlvl.read(rs); 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) if (nameEnt)
{ {
DNAMP1::STRG mlvlName; DNAMP1::STRG mlvlName;
rs.seek(nameEnt->offset, Athena::Begin); NOD::AthenaPartReadStream rs(item.second->node.beginReadStream(nameEnt->offset));
mlvlName.read(rs); mlvlName.read(rs);
if (childRep.desc.size()) if (childRep.desc.size())
childRep.desc += _S(", "); childRep.desc += _S(", ");

View File

@ -4,5 +4,5 @@ static HECL::Database::DataSpecEntry SpecMP2
( (
_S("MP2"), _S("MP2"),
_S("Data specification for original Metroid Prime 2 engine"), _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;}
); );

View File

@ -4,6 +4,6 @@ static HECL::Database::DataSpecEntry SpecMP3
( (
_S("MP3"), _S("MP3"),
_S("Data specification for original Metroid Prime 3 engine"), _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;}
); );