2015-07-06 01:33:06 +00:00
|
|
|
#ifndef __DNAMP1_PAK_HPP__
|
|
|
|
#define __DNAMP1_PAK_HPP__
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2015-07-14 00:38:48 +00:00
|
|
|
#include <NOD/DiscBase.hpp>
|
2015-08-22 01:58:41 +00:00
|
|
|
#include "../DNACommon/PAK.hpp"
|
2015-07-06 01:33:06 +00:00
|
|
|
|
|
|
|
namespace Retro
|
|
|
|
{
|
|
|
|
namespace DNAMP1
|
|
|
|
{
|
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
struct PAK : BigDNA
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2015-07-18 04:33:38 +00:00
|
|
|
bool m_useLzo;
|
2015-09-21 23:36:15 +00:00
|
|
|
bool m_noShare;
|
|
|
|
PAK(bool useLzo, bool noShare) : m_useLzo(useLzo), m_noShare(noShare) {}
|
2015-07-12 04:26:26 +00:00
|
|
|
DECL_EXPLICIT_DNA
|
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
struct NameEntry : BigDNA
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2015-07-06 02:07:57 +00:00
|
|
|
DECL_DNA
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC type;
|
2015-07-06 01:33:06 +00:00
|
|
|
UniqueID32 id;
|
|
|
|
Value<atUint32> nameLen;
|
|
|
|
String<DNA_COUNT(nameLen)> name;
|
|
|
|
};
|
|
|
|
|
2015-07-07 03:22:44 +00:00
|
|
|
struct Entry : BigDNA
|
2015-07-06 01:33:06 +00:00
|
|
|
{
|
2015-07-06 02:07:57 +00:00
|
|
|
DECL_DNA
|
2015-07-06 01:33:06 +00:00
|
|
|
Value<atUint32> compressed;
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC type;
|
2015-07-06 01:33:06 +00:00
|
|
|
UniqueID32 id;
|
|
|
|
Value<atUint32> size;
|
|
|
|
Value<atUint32> offset;
|
2015-08-04 02:14:47 +00:00
|
|
|
UniqueResult unique;
|
2015-07-14 00:38:48 +00:00
|
|
|
|
2015-10-04 05:08:56 +00:00
|
|
|
std::unique_ptr<atUint8[]> getBuffer(const NOD::Node& pak, atUint64& szOut) const;
|
|
|
|
inline PAKEntryReadStream beginReadStream(const NOD::Node& pak, atUint64 off=0) const
|
2015-07-14 00:38:48 +00:00
|
|
|
{
|
|
|
|
atUint64 sz;
|
2015-07-18 04:33:38 +00:00
|
|
|
std::unique_ptr<atUint8[]> buf = getBuffer(pak, sz);
|
|
|
|
return PAKEntryReadStream(std::move(buf), sz, off);
|
2015-07-14 00:38:48 +00:00
|
|
|
}
|
2015-07-06 01:33:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<NameEntry> m_nameEntries;
|
|
|
|
std::vector<Entry> m_entries;
|
2015-10-26 02:31:09 +00:00
|
|
|
std::vector<Entry*> m_firstEntries;
|
2015-07-06 01:33:06 +00:00
|
|
|
std::unordered_map<UniqueID32, Entry*> m_idMap;
|
|
|
|
std::unordered_map<std::string, Entry*> m_nameMap;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2015-07-17 00:01:05 +00:00
|
|
|
|
|
|
|
inline std::string bestEntryName(const Entry& entry) const
|
|
|
|
{
|
|
|
|
/* Prefer named entries first */
|
|
|
|
for (const NameEntry& nentry : m_nameEntries)
|
|
|
|
if (nentry.id == entry.id)
|
|
|
|
return nentry.name;
|
|
|
|
|
|
|
|
/* Otherwise return ID format string */
|
2015-07-18 04:33:38 +00:00
|
|
|
return entry.type.toString() + '_' + entry.id.toString();
|
2015-07-17 00:01:05 +00:00
|
|
|
}
|
2015-07-28 23:53:57 +00:00
|
|
|
|
|
|
|
typedef UniqueID32 IDType;
|
2015-07-06 01:33:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __DNAMP1_PAK_HPP__
|