2015-07-06 01:33:06 +00:00
|
|
|
#ifndef __DNAMP1_PAK_HPP__
|
|
|
|
#define __DNAMP1_PAK_HPP__
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "../Logging.hpp"
|
|
|
|
#include "../DNACommon/DNACommon.hpp"
|
|
|
|
|
|
|
|
namespace Retro
|
|
|
|
{
|
|
|
|
namespace DNAMP1
|
|
|
|
{
|
|
|
|
|
|
|
|
class PAK : public BigDNA
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct NameEntry : public BigDNA
|
|
|
|
{
|
2015-07-06 02:07:57 +00:00
|
|
|
DECL_DNA
|
2015-07-06 01:33:06 +00:00
|
|
|
HECL::FourCC type;
|
|
|
|
UniqueID32 id;
|
|
|
|
Value<atUint32> nameLen;
|
|
|
|
String<DNA_COUNT(nameLen)> name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Entry : public BigDNA
|
|
|
|
{
|
2015-07-06 02:07:57 +00:00
|
|
|
DECL_DNA
|
2015-07-06 01:33:06 +00:00
|
|
|
Value<atUint32> compressed;
|
|
|
|
HECL::FourCC type;
|
|
|
|
UniqueID32 id;
|
|
|
|
Value<atUint32> size;
|
|
|
|
Value<atUint32> offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<NameEntry> m_nameEntries;
|
|
|
|
std::vector<Entry> m_entries;
|
|
|
|
std::unordered_map<UniqueID32, Entry*> m_idMap;
|
|
|
|
std::unordered_map<std::string, Entry*> m_nameMap;
|
|
|
|
Delete expl;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void read(Athena::io::IStreamReader& reader)
|
|
|
|
{
|
|
|
|
reader.setEndian(Athena::BigEndian);
|
|
|
|
atUint32 version = reader.readUint32();
|
|
|
|
if (version != 0x00030005)
|
|
|
|
LogModule.report(LogVisor::FatalError, "unexpected PAK magic");
|
|
|
|
reader.readUint32();
|
|
|
|
|
|
|
|
atUint32 nameCount = reader.readUint32();
|
|
|
|
m_nameEntries.clear();
|
|
|
|
m_nameEntries.reserve(nameCount);
|
|
|
|
for (atUint32 n=0 ; n<nameCount ; ++n)
|
|
|
|
{
|
|
|
|
m_nameEntries.emplace_back();
|
|
|
|
m_nameEntries.back().read(reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
atUint32 count = reader.readUint32();
|
|
|
|
m_entries.clear();
|
|
|
|
m_entries.reserve(count);
|
|
|
|
m_idMap.clear();
|
|
|
|
m_idMap.reserve(count);
|
|
|
|
for (atUint32 e=0 ; e<count ; ++e)
|
|
|
|
{
|
|
|
|
m_entries.emplace_back();
|
|
|
|
m_entries.back().read(reader);
|
|
|
|
m_idMap[m_entries.back().id] = &m_entries.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_nameMap.clear();
|
|
|
|
m_nameMap.reserve(nameCount);
|
|
|
|
for (NameEntry& entry : m_nameEntries)
|
|
|
|
{
|
2015-07-06 02:07:57 +00:00
|
|
|
std::unordered_map<UniqueID32, Entry*>::iterator found = m_idMap.find(entry.id);
|
2015-07-06 01:33:06 +00:00
|
|
|
if (found != m_idMap.end())
|
2015-07-06 02:07:57 +00:00
|
|
|
m_nameMap[entry.name] = found->second;
|
2015-07-06 01:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-06 02:07:57 +00:00
|
|
|
void write(Athena::io::IStreamWriter& writer)
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
|
|
|
writer.setEndian(Athena::BigEndian);
|
|
|
|
writer.writeUint32(0x00030005);
|
|
|
|
writer.writeUint32(0);
|
|
|
|
|
|
|
|
writer.writeUint32(m_nameEntries.size());
|
|
|
|
for (NameEntry& entry : m_nameEntries)
|
2015-07-06 02:07:57 +00:00
|
|
|
{
|
|
|
|
entry.nameLen = entry.name.size();
|
2015-07-06 01:33:06 +00:00
|
|
|
entry.write(writer);
|
2015-07-06 02:07:57 +00:00
|
|
|
}
|
2015-07-06 01:33:06 +00:00
|
|
|
|
|
|
|
writer.writeUint32(m_entries.size());
|
2015-07-06 02:07:57 +00:00
|
|
|
for (const Entry& entry : m_entries)
|
2015-07-06 01:33:06 +00:00
|
|
|
entry.write(writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Entry* lookupEntry(const UniqueID32& id) const
|
|
|
|
{
|
2015-07-06 02:07:57 +00:00
|
|
|
std::unordered_map<UniqueID32, Entry*>::const_iterator result = m_idMap.find(id);
|
2015-07-06 01:33:06 +00:00
|
|
|
if (result != m_idMap.end())
|
2015-07-06 02:07:57 +00:00
|
|
|
return result->second;
|
2015-07-06 01:33:06 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const Entry* lookupEntry(const std::string& name) const
|
|
|
|
{
|
2015-07-06 02:07:57 +00:00
|
|
|
std::unordered_map<std::string, Entry*>::const_iterator result = m_nameMap.find(name);
|
2015-07-06 01:33:06 +00:00
|
|
|
if (result != m_nameMap.end())
|
2015-07-06 02:07:57 +00:00
|
|
|
return result->second;
|
2015-07-06 01:33:06 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __DNAMP1_PAK_HPP__
|