2015-07-18 04:33:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-07-17 00:01:05 +00:00
|
|
|
#define NOD_ATHENA 1
|
2015-07-16 01:57:34 +00:00
|
|
|
#include "DNAMP1.hpp"
|
2015-07-17 00:01:05 +00:00
|
|
|
#include "STRG.hpp"
|
|
|
|
#include "MLVL.hpp"
|
2015-07-19 06:19:46 +00:00
|
|
|
#include "../DNACommon/TXTR.hpp"
|
2015-07-16 01:57:34 +00:00
|
|
|
|
|
|
|
namespace Retro
|
|
|
|
{
|
|
|
|
namespace DNAMP1
|
|
|
|
{
|
|
|
|
LogVisor::LogModule Log("Retro::DNAMP1");
|
2015-07-17 00:01:05 +00:00
|
|
|
|
|
|
|
PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPartition::Node& node)
|
2015-07-18 04:33:38 +00:00
|
|
|
: m_project(project), m_node(node), m_pak(false)
|
2015-07-17 00:01:05 +00:00
|
|
|
{
|
|
|
|
NOD::AthenaPartReadStream rs(node.beginReadStream());
|
|
|
|
m_pak.read(rs);
|
|
|
|
}
|
|
|
|
|
2015-07-19 06:19:46 +00:00
|
|
|
HECL::SystemString PAKBridge::getLevelString() const
|
2015-07-17 00:01:05 +00:00
|
|
|
{
|
2015-07-19 06:19:46 +00:00
|
|
|
HECL::SystemString retval;
|
2015-07-17 00:01:05 +00:00
|
|
|
for (const PAK::Entry& entry : m_pak.m_entries)
|
|
|
|
{
|
|
|
|
if (entry.type == Retro::MLVL)
|
|
|
|
{
|
|
|
|
PAKEntryReadStream rs = entry.beginReadStream(m_node);
|
|
|
|
MLVL mlvl;
|
|
|
|
mlvl.read(rs);
|
|
|
|
const PAK::Entry* nameEnt = m_pak.lookupEntry(mlvl.worldNameId);
|
|
|
|
if (nameEnt)
|
|
|
|
{
|
|
|
|
PAKEntryReadStream rs = nameEnt->beginReadStream(m_node);
|
|
|
|
STRG mlvlName;
|
|
|
|
mlvlName.read(rs);
|
|
|
|
if (retval.size())
|
|
|
|
retval += _S(", ");
|
2015-07-19 06:19:46 +00:00
|
|
|
retval += mlvlName.getSystemString(ENGL, 0);
|
2015-07-17 00:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResExtractor PAKBridge::LookupExtractor(const PAK::Entry& entry)
|
|
|
|
{
|
2015-07-19 06:19:46 +00:00
|
|
|
switch (entry.type.toUint32())
|
|
|
|
{
|
|
|
|
case SBIG('STRG'):
|
2015-07-22 19:05:18 +00:00
|
|
|
return {STRG::Extract, ".as"};
|
2015-07-19 06:19:46 +00:00
|
|
|
case SBIG('TXTR'):
|
|
|
|
return {TXTR::Extract, ".png"};
|
|
|
|
}
|
2015-07-17 00:01:05 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2015-07-18 04:33:38 +00:00
|
|
|
bool PAKBridge::extractResources(const HECL::ProjectPath& workingOut,
|
|
|
|
const HECL::ProjectPath& cookedOut,
|
2015-07-20 23:25:16 +00:00
|
|
|
bool force,
|
|
|
|
std::function<void(float)> progress)
|
2015-07-17 00:01:05 +00:00
|
|
|
{
|
2015-07-20 23:25:16 +00:00
|
|
|
size_t count = 0;
|
2015-07-17 00:01:05 +00:00
|
|
|
for (const std::pair<UniqueID32, PAK::Entry*>& item : m_pak.m_idMap)
|
|
|
|
{
|
2015-07-18 04:33:38 +00:00
|
|
|
PAKEntryReadStream s;
|
2015-07-17 00:01:05 +00:00
|
|
|
ResExtractor extractor = LookupExtractor(*item.second);
|
|
|
|
if (extractor.func)
|
|
|
|
{
|
2015-07-18 04:33:38 +00:00
|
|
|
HECL::ProjectPath workPath(workingOut, m_pak.bestEntryName(*item.second) + extractor.fileExt);
|
|
|
|
if (force || workPath.getPathType() == HECL::ProjectPath::PT_NONE)
|
|
|
|
{
|
|
|
|
s = item.second->beginReadStream(m_node);
|
|
|
|
extractor.func(s, workPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HECL::ProjectPath cookPath(cookedOut, m_pak.bestEntryName(*item.second));
|
|
|
|
if (force || cookPath.getPathType() == HECL::ProjectPath::PT_NONE)
|
|
|
|
{
|
|
|
|
if (!s)
|
|
|
|
s = item.second->beginReadStream(m_node);
|
|
|
|
FILE* fout = HECL::Fopen(cookPath.getAbsolutePath().c_str(), _S("wb"));
|
|
|
|
fwrite(s.data(), 1, s.length(), fout);
|
|
|
|
fclose(fout);
|
2015-07-17 00:01:05 +00:00
|
|
|
}
|
2015-07-20 23:25:16 +00:00
|
|
|
|
|
|
|
++count;
|
|
|
|
progress(count / (float)m_pak.m_idMap.size());
|
2015-07-17 00:01:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-16 01:57:34 +00:00
|
|
|
}
|
|
|
|
}
|