2015-06-24 20:56:23 +00:00
|
|
|
#ifndef __DNA_COMMON_HPP__
|
|
|
|
#define __DNA_COMMON_HPP__
|
|
|
|
|
2015-07-29 20:45:47 +00:00
|
|
|
#include <stdio.h>
|
2015-08-01 00:38:35 +00:00
|
|
|
#include <Athena/DNAYaml.hpp>
|
2015-07-29 20:45:47 +00:00
|
|
|
#include <NOD/DiscBase.hpp>
|
2015-07-06 01:33:06 +00:00
|
|
|
#include "HECL/HECL.hpp"
|
2015-07-17 00:01:05 +00:00
|
|
|
#include "HECL/Database.hpp"
|
2015-08-05 21:46:07 +00:00
|
|
|
#include "../SpecBase.hpp"
|
2015-06-24 20:56:23 +00:00
|
|
|
|
2015-07-01 23:50:39 +00:00
|
|
|
namespace Retro
|
|
|
|
{
|
|
|
|
|
2015-07-16 01:57:34 +00:00
|
|
|
extern LogVisor::LogModule LogDNACommon;
|
|
|
|
|
2015-06-24 20:56:23 +00:00
|
|
|
/* This comes up a great deal */
|
|
|
|
typedef Athena::io::DNA<Athena::BigEndian> BigDNA;
|
2015-08-01 00:38:35 +00:00
|
|
|
typedef Athena::io::DNAYaml<Athena::BigEndian> BigYAML;
|
2015-06-24 20:56:23 +00:00
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
/* FourCC with DNA read/write */
|
2015-08-01 00:38:35 +00:00
|
|
|
class FourCC final : public BigYAML, public HECL::FourCC
|
2015-07-11 22:41:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FourCC() : HECL::FourCC() {}
|
2015-07-13 06:29:12 +00:00
|
|
|
FourCC(const HECL::FourCC& other)
|
|
|
|
: HECL::FourCC() {num = other.toUint32();}
|
2015-07-11 22:41:10 +00:00
|
|
|
FourCC(const char* name)
|
|
|
|
: HECL::FourCC(name) {}
|
|
|
|
|
|
|
|
Delete expl;
|
|
|
|
inline void read(Athena::io::IStreamReader& reader)
|
|
|
|
{reader.readUBytesToBuf(fcc, 4);}
|
|
|
|
inline void write(Athena::io::IStreamWriter& writer) const
|
|
|
|
{writer.writeUBytes((atUint8*)fcc, 4);}
|
2015-08-01 00:38:35 +00:00
|
|
|
inline void fromYAML(Athena::io::YAMLDocReader& reader)
|
|
|
|
{std::string rs = reader.readString(nullptr); strncpy(fcc, rs.c_str(), 4);}
|
|
|
|
inline void toYAML(Athena::io::YAMLDocWriter& writer) const
|
|
|
|
{writer.writeString(nullptr, std::string(fcc, 4));}
|
2015-07-11 22:41:10 +00:00
|
|
|
};
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
/* PAK 32-bit Unique ID */
|
2015-08-01 00:38:35 +00:00
|
|
|
class UniqueID32 : public BigYAML
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-08-08 04:49:42 +00:00
|
|
|
uint32_t m_id = 0;
|
2015-06-24 20:56:23 +00:00
|
|
|
public:
|
|
|
|
Delete expl;
|
2015-08-08 04:49:42 +00:00
|
|
|
inline operator bool() const {return m_id;}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline void read(Athena::io::IStreamReader& reader)
|
2015-07-12 04:26:26 +00:00
|
|
|
{m_id = reader.readUint32();}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline void write(Athena::io::IStreamWriter& writer) const
|
|
|
|
{writer.writeUint32(m_id);}
|
2015-08-01 00:38:35 +00:00
|
|
|
inline void fromYAML(Athena::io::YAMLDocReader& reader)
|
|
|
|
{m_id = reader.readUint32(nullptr);}
|
|
|
|
inline void toYAML(Athena::io::YAMLDocWriter& writer) const
|
|
|
|
{writer.writeUint32(nullptr, m_id);}
|
2015-07-06 01:33:06 +00:00
|
|
|
|
|
|
|
inline bool operator!=(const UniqueID32& other) const {return m_id != other.m_id;}
|
|
|
|
inline bool operator==(const UniqueID32& other) const {return m_id == other.m_id;}
|
2015-07-06 02:07:57 +00:00
|
|
|
inline uint32_t toUint32() const {return m_id;}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline std::string toString() const
|
|
|
|
{
|
|
|
|
char buf[9];
|
|
|
|
snprintf(buf, 9, "%08X", m_id);
|
|
|
|
return std::string(buf);
|
|
|
|
}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
/* PAK 64-bit Unique ID */
|
|
|
|
class UniqueID64 : public BigDNA
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-08-08 04:49:42 +00:00
|
|
|
uint64_t m_id = 0;
|
2015-06-24 20:56:23 +00:00
|
|
|
public:
|
|
|
|
Delete expl;
|
2015-08-08 04:49:42 +00:00
|
|
|
inline operator bool() const {return m_id;}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline void read(Athena::io::IStreamReader& reader)
|
2015-07-12 04:26:26 +00:00
|
|
|
{m_id = reader.readUint64();}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline void write(Athena::io::IStreamWriter& writer) const
|
|
|
|
{writer.writeUint64(m_id);}
|
|
|
|
|
|
|
|
inline bool operator!=(const UniqueID64& other) const {return m_id != other.m_id;}
|
|
|
|
inline bool operator==(const UniqueID64& other) const {return m_id == other.m_id;}
|
2015-07-06 02:07:57 +00:00
|
|
|
inline uint64_t toUint64() const {return m_id;}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline std::string toString() const
|
|
|
|
{
|
|
|
|
char buf[17];
|
2015-07-19 10:43:37 +00:00
|
|
|
snprintf(buf, 17, "%016lX", m_id);
|
2015-07-06 01:33:06 +00:00
|
|
|
return std::string(buf);
|
|
|
|
}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
/* PAK 128-bit Unique ID */
|
|
|
|
class UniqueID128 : public BigDNA
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-07-06 01:33:06 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
uint64_t m_id[2];
|
|
|
|
#if __SSE__
|
|
|
|
__m128i m_id128;
|
|
|
|
#endif
|
|
|
|
};
|
2015-06-24 20:56:23 +00:00
|
|
|
public:
|
|
|
|
Delete expl;
|
2015-08-08 04:49:42 +00:00
|
|
|
UniqueID128() {m_id[0]=0; m_id[1]=0;}
|
|
|
|
inline operator bool() const {return m_id[0] && m_id[1];}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline void read(Athena::io::IStreamReader& reader)
|
|
|
|
{
|
|
|
|
m_id[0] = reader.readUint64();
|
|
|
|
m_id[1] = reader.readUint64();
|
|
|
|
}
|
|
|
|
inline void write(Athena::io::IStreamWriter& writer) const
|
|
|
|
{
|
|
|
|
writer.writeUint64(m_id[0]);
|
|
|
|
writer.writeUint64(m_id[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const UniqueID128& other) const
|
|
|
|
{
|
|
|
|
#if __SSE__
|
2015-07-06 02:07:57 +00:00
|
|
|
__m128i vcmp = _mm_cmpeq_epi32(m_id128, other.m_id128);
|
|
|
|
int vmask = _mm_movemask_epi8(vcmp);
|
|
|
|
return vmask != 0xffff;
|
2015-07-06 01:33:06 +00:00
|
|
|
#else
|
|
|
|
return (m_id[0] != other.m_id[0]) || (m_id[1] != other.m_id[1]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
inline bool operator==(const UniqueID128& other) const
|
|
|
|
{
|
|
|
|
#if __SSE__
|
2015-07-06 02:07:57 +00:00
|
|
|
__m128i vcmp = _mm_cmpeq_epi32(m_id128, other.m_id128);
|
|
|
|
int vmask = _mm_movemask_epi8(vcmp);
|
|
|
|
return vmask == 0xffff;
|
2015-07-06 01:33:06 +00:00
|
|
|
#else
|
|
|
|
return (m_id[0] == other.m_id[0]) && (m_id[1] == other.m_id[1]);
|
|
|
|
#endif
|
|
|
|
}
|
2015-07-06 02:07:57 +00:00
|
|
|
inline uint64_t toHighUint64() const {return m_id[0];}
|
|
|
|
inline uint64_t toLowUint64() const {return m_id[1];}
|
2015-07-06 01:33:06 +00:00
|
|
|
inline std::string toString() const
|
|
|
|
{
|
|
|
|
char buf[33];
|
2015-07-19 10:43:37 +00:00
|
|
|
snprintf(buf, 33, "%016lX%016lX", m_id[0], m_id[1]);
|
2015-07-06 01:33:06 +00:00
|
|
|
return std::string(buf);
|
|
|
|
}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-07-14 00:38:48 +00:00
|
|
|
/* Case-insensitive comparator for std::map sorting */
|
2015-07-10 05:28:08 +00:00
|
|
|
struct CaseInsensitiveCompare
|
|
|
|
{
|
|
|
|
inline bool operator()(const std::string& lhs, const std::string& rhs) const
|
|
|
|
{
|
2015-07-14 00:38:48 +00:00
|
|
|
#if _WIN32
|
2015-07-22 19:05:18 +00:00
|
|
|
if (_stricmp(lhs.c_str(), rhs.c_str()) < 0)
|
2015-07-14 00:38:48 +00:00
|
|
|
#else
|
|
|
|
if (strcasecmp(lhs.c_str(), rhs.c_str()) < 0)
|
|
|
|
#endif
|
2015-07-10 05:28:08 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-22 19:05:18 +00:00
|
|
|
|
|
|
|
#if _WIN32
|
|
|
|
inline bool operator()(const std::wstring& lhs, const std::wstring& rhs) const
|
|
|
|
{
|
|
|
|
if (_wcsicmp(lhs.c_str(), rhs.c_str()) < 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-10 05:28:08 +00:00
|
|
|
};
|
2015-07-14 00:38:48 +00:00
|
|
|
|
|
|
|
/* PAK entry stream reader */
|
|
|
|
class PAKEntryReadStream : public Athena::io::IStreamReader
|
|
|
|
{
|
|
|
|
std::unique_ptr<atUint8[]> m_buf;
|
|
|
|
atUint64 m_sz;
|
|
|
|
atUint64 m_pos;
|
|
|
|
public:
|
2015-07-18 04:33:38 +00:00
|
|
|
PAKEntryReadStream() {}
|
|
|
|
operator bool() const {return m_buf.operator bool();}
|
|
|
|
PAKEntryReadStream(const PAKEntryReadStream& other) = delete;
|
|
|
|
PAKEntryReadStream(PAKEntryReadStream&& other) = default;
|
|
|
|
PAKEntryReadStream& operator=(const PAKEntryReadStream& other) = delete;
|
|
|
|
PAKEntryReadStream& operator=(PAKEntryReadStream&& other) = default;
|
2015-07-14 00:38:48 +00:00
|
|
|
PAKEntryReadStream(std::unique_ptr<atUint8[]>&& buf, atUint64 sz, atUint64 pos)
|
|
|
|
: m_buf(std::move(buf)), m_sz(sz), m_pos(pos)
|
|
|
|
{
|
|
|
|
if (m_pos >= m_sz)
|
2015-07-16 01:57:34 +00:00
|
|
|
LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun");
|
2015-07-14 00:38:48 +00:00
|
|
|
}
|
|
|
|
inline void seek(atInt64 pos, Athena::SeekOrigin origin)
|
|
|
|
{
|
|
|
|
if (origin == Athena::Begin)
|
|
|
|
m_pos = pos;
|
|
|
|
else if (origin == Athena::Current)
|
|
|
|
m_pos += pos;
|
|
|
|
else if (origin == Athena::End)
|
|
|
|
m_pos = m_sz + pos;
|
|
|
|
if (m_pos >= m_sz)
|
2015-07-16 01:57:34 +00:00
|
|
|
LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun");
|
2015-07-14 00:38:48 +00:00
|
|
|
}
|
|
|
|
inline atUint64 position() const {return m_pos;}
|
|
|
|
inline atUint64 length() const {return m_sz;}
|
2015-07-18 04:33:38 +00:00
|
|
|
inline const atUint8* data() const {return m_buf.get();}
|
2015-07-14 00:38:48 +00:00
|
|
|
inline atUint64 readUBytesToBuf(void* buf, atUint64 len)
|
|
|
|
{
|
|
|
|
atUint64 bufEnd = m_pos + len;
|
|
|
|
if (bufEnd > m_sz)
|
|
|
|
len -= bufEnd - m_sz;
|
|
|
|
memcpy(buf, m_buf.get() + m_pos, len);
|
|
|
|
m_pos += len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
};
|
2015-07-17 00:01:05 +00:00
|
|
|
|
2015-08-04 02:14:47 +00:00
|
|
|
struct UniqueResult
|
|
|
|
{
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
UNIQUE_NOTFOUND,
|
|
|
|
UNIQUE_LEVEL,
|
|
|
|
UNIQUE_AREA,
|
|
|
|
UNIQUE_LAYER
|
|
|
|
} type = UNIQUE_NOTFOUND;
|
|
|
|
const HECL::SystemString* areaName = nullptr;
|
|
|
|
const HECL::SystemString* layerName = nullptr;
|
|
|
|
UniqueResult() = default;
|
|
|
|
UniqueResult(Type tp) : type(tp) {}
|
|
|
|
inline HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const
|
|
|
|
{
|
|
|
|
if (type == UNIQUE_AREA)
|
|
|
|
{
|
|
|
|
HECL::ProjectPath areaDir(pakPath, *areaName);
|
|
|
|
areaDir.makeDir();
|
|
|
|
return areaDir;
|
|
|
|
}
|
|
|
|
else if (type == UNIQUE_LAYER)
|
|
|
|
{
|
|
|
|
HECL::ProjectPath areaDir(pakPath, *areaName);
|
|
|
|
areaDir.makeDir();
|
|
|
|
HECL::ProjectPath layerDir(areaDir, *layerName);
|
|
|
|
layerDir.makeDir();
|
|
|
|
return layerDir;
|
|
|
|
}
|
|
|
|
return pakPath;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class BRIDGETYPE>
|
|
|
|
class PAKRouter;
|
|
|
|
|
2015-07-17 00:01:05 +00:00
|
|
|
/* Resource extractor type */
|
2015-08-04 02:14:47 +00:00
|
|
|
template <class PAKBRIDGE>
|
|
|
|
struct ResExtractor
|
2015-07-17 00:01:05 +00:00
|
|
|
{
|
2015-08-05 21:46:07 +00:00
|
|
|
std::function<bool(const SpecBase&, PAKEntryReadStream&, const HECL::ProjectPath&)> func_a;
|
|
|
|
std::function<bool(const SpecBase&, PAKEntryReadStream&, const HECL::ProjectPath&, PAKRouter<PAKBRIDGE>&,
|
2015-08-04 21:35:41 +00:00
|
|
|
const typename PAKBRIDGE::PAKType::Entry&)> func_b;
|
2015-07-17 00:01:05 +00:00
|
|
|
const char* fileExt;
|
2015-07-29 20:45:47 +00:00
|
|
|
unsigned weight;
|
2015-08-04 02:14:47 +00:00
|
|
|
};
|
2015-07-17 00:01:05 +00:00
|
|
|
|
2015-07-28 23:53:57 +00:00
|
|
|
/* PAKRouter (for detecting shared entry locations) */
|
|
|
|
template <class BRIDGETYPE>
|
|
|
|
class PAKRouter
|
|
|
|
{
|
2015-08-10 01:53:24 +00:00
|
|
|
public:
|
|
|
|
using PAKType = typename BRIDGETYPE::PAKType;
|
|
|
|
using IDType = typename PAKType::IDType;
|
|
|
|
using EntryType = typename PAKType::Entry;
|
|
|
|
private:
|
2015-08-05 21:46:07 +00:00
|
|
|
const SpecBase& m_dataSpec;
|
2015-07-28 23:53:57 +00:00
|
|
|
const HECL::ProjectPath& m_gameWorking;
|
|
|
|
const HECL::ProjectPath& m_gameCooked;
|
|
|
|
HECL::ProjectPath m_sharedWorking;
|
|
|
|
HECL::ProjectPath m_sharedCooked;
|
2015-08-10 01:53:24 +00:00
|
|
|
const PAKType* m_pak = nullptr;
|
2015-07-29 20:45:47 +00:00
|
|
|
const NOD::DiscBase::IPartition::Node* m_node = nullptr;
|
2015-07-28 23:53:57 +00:00
|
|
|
HECL::ProjectPath m_pakWorking;
|
|
|
|
HECL::ProjectPath m_pakCooked;
|
2015-08-10 01:53:24 +00:00
|
|
|
std::unordered_map<typename PAKType::IDType, typename PAKType::Entry*> m_uniqueEntries;
|
|
|
|
std::unordered_map<IDType, EntryType*> m_sharedEntries;
|
2015-07-28 23:53:57 +00:00
|
|
|
public:
|
2015-08-05 21:46:07 +00:00
|
|
|
PAKRouter(const SpecBase& dataSpec, const HECL::ProjectPath& working, const HECL::ProjectPath& cooked)
|
|
|
|
: m_dataSpec(dataSpec),
|
|
|
|
m_gameWorking(working), m_gameCooked(cooked),
|
2015-07-28 23:53:57 +00:00
|
|
|
m_sharedWorking(working, "Shared"), m_sharedCooked(cooked, "Shared") {}
|
2015-08-04 02:14:47 +00:00
|
|
|
void build(std::vector<BRIDGETYPE>& bridges, std::function<void(float)> progress)
|
2015-07-28 23:53:57 +00:00
|
|
|
{
|
|
|
|
m_uniqueEntries.clear();
|
|
|
|
m_sharedEntries.clear();
|
|
|
|
size_t count = 0;
|
|
|
|
float bridgesSz = bridges.size();
|
2015-08-04 02:14:47 +00:00
|
|
|
|
|
|
|
/* Route entries unique/shared per-pak */
|
|
|
|
for (BRIDGETYPE& bridge : bridges)
|
2015-07-28 23:53:57 +00:00
|
|
|
{
|
2015-08-04 02:14:47 +00:00
|
|
|
bridge.build();
|
2015-07-28 23:53:57 +00:00
|
|
|
const typename BRIDGETYPE::PAKType& pak = bridge.getPAK();
|
|
|
|
for (const auto& entry : pak.m_idMap)
|
|
|
|
{
|
|
|
|
auto search = m_uniqueEntries.find(entry.first);
|
|
|
|
if (search != m_uniqueEntries.end())
|
|
|
|
{
|
|
|
|
m_uniqueEntries.erase(search);
|
|
|
|
m_sharedEntries.insert(entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_uniqueEntries.insert(entry);
|
|
|
|
}
|
|
|
|
progress(++count / bridgesSz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void enterPAKBridge(const BRIDGETYPE& pakBridge)
|
|
|
|
{
|
|
|
|
const std::string& name = pakBridge.getName();
|
|
|
|
HECL::SystemStringView sysName(name);
|
|
|
|
|
|
|
|
HECL::SystemString::const_iterator extit = sysName.sys_str().end() - 4;
|
|
|
|
HECL::SystemString baseName(sysName.sys_str().begin(), extit);
|
|
|
|
|
|
|
|
m_pakWorking.assign(m_gameWorking, baseName);
|
|
|
|
m_pakWorking.makeDir();
|
|
|
|
m_pakCooked.assign(m_gameCooked, baseName);
|
|
|
|
m_pakCooked.makeDir();
|
|
|
|
|
2015-07-29 20:45:47 +00:00
|
|
|
m_pak = &pakBridge.getPAK();
|
|
|
|
m_node = &pakBridge.getNode();
|
2015-07-28 23:53:57 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 20:45:47 +00:00
|
|
|
HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry,
|
2015-08-04 02:14:47 +00:00
|
|
|
const ResExtractor<BRIDGETYPE>& extractor) const
|
2015-07-28 23:53:57 +00:00
|
|
|
{
|
|
|
|
if (!m_pak)
|
|
|
|
LogDNACommon.report(LogVisor::FatalError,
|
|
|
|
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getWorkingPath()");
|
2015-07-29 20:45:47 +00:00
|
|
|
auto uniqueSearch = m_uniqueEntries.find(entry->id);
|
2015-07-28 23:53:57 +00:00
|
|
|
if (uniqueSearch != m_uniqueEntries.end())
|
|
|
|
{
|
2015-08-04 02:14:47 +00:00
|
|
|
HECL::ProjectPath uniquePath = entry->unique.uniquePath(m_pakWorking);
|
2015-07-29 20:45:47 +00:00
|
|
|
HECL::SystemString entName = m_pak->bestEntryName(*entry);
|
2015-07-28 23:53:57 +00:00
|
|
|
if (extractor.fileExt)
|
|
|
|
entName += extractor.fileExt;
|
2015-08-04 02:14:47 +00:00
|
|
|
return HECL::ProjectPath(uniquePath, entName);
|
2015-07-28 23:53:57 +00:00
|
|
|
}
|
2015-07-29 20:45:47 +00:00
|
|
|
auto sharedSearch = m_sharedEntries.find(entry->id);
|
2015-07-28 23:53:57 +00:00
|
|
|
if (sharedSearch != m_sharedEntries.end())
|
|
|
|
{
|
2015-08-04 02:46:48 +00:00
|
|
|
HECL::ProjectPath uniquePathPre = entry->unique.uniquePath(m_pakWorking);
|
2015-07-29 20:45:47 +00:00
|
|
|
HECL::SystemString entName = m_pak->bestEntryName(*entry);
|
2015-07-28 23:53:57 +00:00
|
|
|
if (extractor.fileExt)
|
|
|
|
entName += extractor.fileExt;
|
|
|
|
HECL::ProjectPath sharedPath(m_sharedWorking, entName);
|
2015-08-04 02:46:48 +00:00
|
|
|
HECL::ProjectPath uniquePath(uniquePathPre, entName);
|
2015-08-04 02:14:47 +00:00
|
|
|
if (extractor.func_a || extractor.func_b)
|
2015-07-28 23:53:57 +00:00
|
|
|
uniquePath.makeLinkTo(sharedPath);
|
|
|
|
m_sharedWorking.makeDir();
|
2015-07-29 20:45:47 +00:00
|
|
|
return sharedPath;
|
2015-07-28 23:53:57 +00:00
|
|
|
}
|
2015-07-29 20:45:47 +00:00
|
|
|
LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str());
|
|
|
|
return HECL::ProjectPath();
|
2015-07-28 23:53:57 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 20:45:47 +00:00
|
|
|
HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::Entry* entry) const
|
2015-07-28 23:53:57 +00:00
|
|
|
{
|
|
|
|
if (!m_pak)
|
|
|
|
LogDNACommon.report(LogVisor::FatalError,
|
|
|
|
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getCookedPath()");
|
2015-07-29 20:45:47 +00:00
|
|
|
auto uniqueSearch = m_uniqueEntries.find(entry->id);
|
2015-07-28 23:53:57 +00:00
|
|
|
if (uniqueSearch != m_uniqueEntries.end())
|
|
|
|
{
|
2015-08-04 02:14:47 +00:00
|
|
|
HECL::ProjectPath uniquePath = entry->unique.uniquePath(m_pakCooked);
|
|
|
|
return HECL::ProjectPath(uniquePath, m_pak->bestEntryName(*entry));
|
2015-07-28 23:53:57 +00:00
|
|
|
}
|
2015-07-29 20:45:47 +00:00
|
|
|
auto sharedSearch = m_sharedEntries.find(entry->id);
|
2015-07-28 23:53:57 +00:00
|
|
|
if (sharedSearch != m_sharedEntries.end())
|
|
|
|
{
|
|
|
|
m_sharedCooked.makeDir();
|
2015-07-29 20:45:47 +00:00
|
|
|
return HECL::ProjectPath(m_sharedCooked, m_pak->bestEntryName(*entry));
|
2015-07-28 23:53:57 +00:00
|
|
|
}
|
2015-07-29 20:45:47 +00:00
|
|
|
LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str());
|
|
|
|
return HECL::ProjectPath();
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:35:41 +00:00
|
|
|
HECL::SystemString getResourceRelativePath(const typename BRIDGETYPE::PAKType::Entry& a,
|
|
|
|
const typename BRIDGETYPE::PAKType::IDType& b) const
|
|
|
|
{
|
|
|
|
if (!m_pak)
|
|
|
|
LogDNACommon.report(LogVisor::FatalError,
|
|
|
|
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getResourceRelativePath()");
|
|
|
|
const typename BRIDGETYPE::PAKType::Entry* be = m_pak->lookupEntry(b);
|
|
|
|
if (!be)
|
|
|
|
return HECL::SystemString();
|
|
|
|
HECL::ProjectPath aPath = getWorking(&a, BRIDGETYPE::LookupExtractor(a));
|
|
|
|
HECL::SystemString ret;
|
|
|
|
for (int i=0 ; i<aPath.levelCount() ; ++i)
|
|
|
|
ret += "../";
|
|
|
|
HECL::ProjectPath bPath = getWorking(be, BRIDGETYPE::LookupExtractor(*be));
|
|
|
|
ret += bPath.getRelativePath();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getBestEntryName(const typename BRIDGETYPE::PAKType::Entry& entry) const
|
|
|
|
{
|
|
|
|
if (!m_pak)
|
|
|
|
LogDNACommon.report(LogVisor::FatalError,
|
|
|
|
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()");
|
|
|
|
return m_pak->bestEntryName(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getBestEntryName(const typename BRIDGETYPE::PAKType::IDType& entry) const
|
|
|
|
{
|
|
|
|
if (!m_pak)
|
|
|
|
LogDNACommon.report(LogVisor::FatalError,
|
|
|
|
"PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()");
|
|
|
|
const typename BRIDGETYPE::PAKType::Entry* e = m_pak->lookupEntry(entry);
|
|
|
|
if (!e)
|
|
|
|
return entry.toString();
|
|
|
|
return m_pak->bestEntryName(*e);
|
|
|
|
}
|
|
|
|
|
2015-07-29 20:45:47 +00:00
|
|
|
bool extractResources(const BRIDGETYPE& pakBridge, bool force, std::function<void(float)> progress)
|
|
|
|
{
|
|
|
|
enterPAKBridge(pakBridge);
|
|
|
|
size_t count = 0;
|
|
|
|
size_t sz = m_pak->m_idMap.size();
|
|
|
|
float fsz = sz;
|
|
|
|
for (unsigned w=0 ; count<sz ; ++w)
|
|
|
|
{
|
|
|
|
for (const auto& item : m_pak->m_idMap)
|
|
|
|
{
|
2015-08-04 02:14:47 +00:00
|
|
|
ResExtractor<BRIDGETYPE> extractor = BRIDGETYPE::LookupExtractor(*item.second);
|
2015-07-29 20:45:47 +00:00
|
|
|
if (extractor.weight != w)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
HECL::ProjectPath cooked = getCooked(item.second);
|
|
|
|
if (force || cooked.getPathType() == HECL::ProjectPath::PT_NONE)
|
|
|
|
{
|
|
|
|
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
|
|
|
FILE* fout = HECL::Fopen(cooked.getAbsolutePath().c_str(), _S("wb"));
|
|
|
|
fwrite(s.data(), 1, s.length(), fout);
|
|
|
|
fclose(fout);
|
|
|
|
}
|
|
|
|
|
|
|
|
HECL::ProjectPath working = getWorking(item.second, extractor);
|
2015-08-04 02:14:47 +00:00
|
|
|
if (extractor.func_a) /* Doesn't need PAKRouter access */
|
|
|
|
{
|
|
|
|
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
|
|
|
{
|
|
|
|
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
2015-08-05 21:46:07 +00:00
|
|
|
extractor.func_a(m_dataSpec, s, working);
|
2015-08-04 02:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (extractor.func_b) /* Needs PAKRouter access */
|
2015-07-29 20:45:47 +00:00
|
|
|
{
|
|
|
|
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
|
|
|
{
|
|
|
|
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
2015-08-05 21:46:07 +00:00
|
|
|
extractor.func_b(m_dataSpec, s, working, *this, *item.second);
|
2015-07-29 20:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
progress(++count / fsz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-07-28 23:53:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-17 00:01:05 +00:00
|
|
|
/* Resource cooker function */
|
|
|
|
typedef std::function<bool(const HECL::ProjectPath&, const HECL::ProjectPath&)> ResCooker;
|
2015-07-10 05:28:08 +00:00
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
/* Language-identifiers */
|
|
|
|
extern const HECL::FourCC ENGL;
|
|
|
|
extern const HECL::FourCC FREN;
|
|
|
|
extern const HECL::FourCC GERM;
|
|
|
|
extern const HECL::FourCC SPAN;
|
|
|
|
extern const HECL::FourCC ITAL;
|
|
|
|
extern const HECL::FourCC JAPN;
|
|
|
|
|
|
|
|
/* Resource types */
|
|
|
|
extern const HECL::FourCC AFSM;
|
|
|
|
extern const HECL::FourCC AGSC;
|
|
|
|
extern const HECL::FourCC ANCS;
|
|
|
|
extern const HECL::FourCC ANIM;
|
|
|
|
extern const HECL::FourCC ATBL;
|
|
|
|
extern const HECL::FourCC CINF;
|
|
|
|
extern const HECL::FourCC CMDL;
|
|
|
|
extern const HECL::FourCC CRSC;
|
|
|
|
extern const HECL::FourCC CSKR;
|
|
|
|
extern const HECL::FourCC CSMP;
|
|
|
|
extern const HECL::FourCC CSNG;
|
|
|
|
extern const HECL::FourCC CTWK;
|
|
|
|
extern const HECL::FourCC DGRP;
|
|
|
|
extern const HECL::FourCC DPSC;
|
|
|
|
extern const HECL::FourCC DUMB;
|
|
|
|
extern const HECL::FourCC ELSC;
|
|
|
|
extern const HECL::FourCC EVNT;
|
|
|
|
extern const HECL::FourCC FONT;
|
|
|
|
extern const HECL::FourCC FRME;
|
|
|
|
extern const HECL::FourCC HINT;
|
|
|
|
extern const HECL::FourCC MAPA;
|
|
|
|
extern const HECL::FourCC MAPU;
|
|
|
|
extern const HECL::FourCC MAPW;
|
|
|
|
extern const HECL::FourCC MLVL;
|
|
|
|
extern const HECL::FourCC MREA;
|
|
|
|
extern const HECL::FourCC PART;
|
|
|
|
extern const HECL::FourCC PATH;
|
|
|
|
extern const HECL::FourCC RFRM;
|
|
|
|
extern const HECL::FourCC ROOM;
|
|
|
|
extern const HECL::FourCC SAVW;
|
|
|
|
extern const HECL::FourCC SCAN;
|
|
|
|
extern const HECL::FourCC STRG;
|
|
|
|
extern const HECL::FourCC SWHC;
|
|
|
|
extern const HECL::FourCC TXTR;
|
|
|
|
extern const HECL::FourCC WPSC;
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Hash template-specializations for UniqueID types */
|
|
|
|
namespace std
|
2015-06-24 20:56:23 +00:00
|
|
|
{
|
2015-07-13 06:29:12 +00:00
|
|
|
template<>
|
|
|
|
struct hash<Retro::FourCC>
|
|
|
|
{
|
|
|
|
inline size_t operator()(const Retro::FourCC& fcc) const
|
|
|
|
{return fcc.toUint32();}
|
|
|
|
};
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
template<>
|
|
|
|
struct hash<Retro::UniqueID32>
|
|
|
|
{
|
|
|
|
inline size_t operator()(const Retro::UniqueID32& id) const
|
2015-07-06 02:07:57 +00:00
|
|
|
{return id.toUint32();}
|
2015-07-06 01:33:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct hash<Retro::UniqueID64>
|
|
|
|
{
|
|
|
|
inline size_t operator()(const Retro::UniqueID64& id) const
|
2015-07-06 02:07:57 +00:00
|
|
|
{return id.toUint64();}
|
2015-06-24 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
2015-07-06 01:33:06 +00:00
|
|
|
template<>
|
|
|
|
struct hash<Retro::UniqueID128>
|
|
|
|
{
|
|
|
|
inline size_t operator()(const Retro::UniqueID128& id) const
|
2015-07-06 02:07:57 +00:00
|
|
|
{return id.toHighUint64() ^ id.toLowUint64();}
|
2015-07-06 01:33:06 +00:00
|
|
|
};
|
2015-07-01 23:50:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-24 20:56:23 +00:00
|
|
|
#endif // __DNA_COMMON_HPP__
|