metaforce/DataSpec/SpecBase.cpp

175 lines
5.3 KiB
C++
Raw Normal View History

2015-07-01 23:50:39 +00:00
#include "SpecBase.hpp"
#include "Blender/BlenderSupport.hpp"
2015-10-01 00:40:21 +00:00
#include "BlenderConnection.hpp"
2015-11-10 02:07:15 +00:00
#include "DNACommon/DNACommon.hpp"
2015-07-01 23:50:39 +00:00
namespace Retro
{
static LogVisor::LogModule Log("Retro::SpecBase");
2015-11-10 02:07:15 +00:00
SpecBase::SpecBase(HECL::Database::Project& project)
: m_project(project),
m_masterShader(project.getProjectWorkingPath(), ".hecl/RetroMasterShader.blend") {}
2015-10-04 05:08:56 +00:00
bool SpecBase::canExtract(const ExtractPassInfo& info, std::vector<ExtractReport>& reps)
2015-07-01 23:50:39 +00:00
{
m_disc = NOD::OpenDiscFromImage(info.srcpath.c_str(), m_isWii);
2015-07-16 01:57:34 +00:00
if (!m_disc)
2015-07-02 20:41:40 +00:00
return false;
2015-07-16 01:57:34 +00:00
const char* gameID = m_disc->getHeader().gameID;
2015-07-02 20:41:40 +00:00
m_standalone = true;
if (m_isWii && !memcmp(gameID, "R3M", 3))
m_standalone = false;
2015-07-01 23:50:39 +00:00
if (m_standalone && !checkStandaloneID(gameID))
2015-07-10 05:28:08 +00:00
return false;
2015-07-16 01:57:34 +00:00
char region = m_disc->getHeader().gameID[3];
static const HECL::SystemString regNONE = _S("");
static const HECL::SystemString regE = _S("NTSC");
static const HECL::SystemString regJ = _S("NTSC-J");
static const HECL::SystemString regP = _S("PAL");
const HECL::SystemString* regstr = &regNONE;
2015-07-12 18:07:58 +00:00
switch (region)
{
case 'E':
regstr = &regE;
break;
case 'J':
regstr = &regJ;
break;
case 'P':
regstr = &regP;
break;
}
if (m_standalone)
2015-08-05 21:46:07 +00:00
return checkFromStandaloneDisc(*m_disc, *regstr, info.extractArgs, reps);
2015-07-10 05:28:08 +00:00
else
2015-08-05 21:46:07 +00:00
return checkFromTrilogyDisc(*m_disc, *regstr, info.extractArgs, reps);
2015-07-01 23:50:39 +00:00
}
2015-09-30 06:23:40 +00:00
void SpecBase::doExtract(const ExtractPassInfo& info, FProgress progress)
2015-07-01 23:50:39 +00:00
{
2015-11-10 02:07:15 +00:00
Retro::g_curSpec = this;
2015-08-05 21:46:07 +00:00
if (!Blender::BuildMasterShader(m_masterShader))
Log.report(LogVisor::FatalError, "Unable to build master shader blend");
if (m_isWii)
{
/* Extract update partition for repacking later */
2015-10-01 00:40:21 +00:00
const HECL::SystemString& target = m_project.getProjectWorkingPath().getAbsolutePath();
2015-10-04 05:08:56 +00:00
NOD::Partition* update = m_disc->getUpdatePartition();
NOD::ExtractionContext ctx = {true, info.force, nullptr};
2015-09-29 03:49:31 +00:00
if (update)
2015-07-20 23:25:16 +00:00
{
atUint64 idx = 0;
2015-09-02 22:00:40 +00:00
progress(_S("Update Partition"), _S(""), 0, 0.0);
const atUint64 nodeCount = update->getFSTRoot().rawEnd() - update->getFSTRoot().rawBegin();
ctx.progressCB = [&](const std::string& name) {
HECL::SystemStringView nameView(name);
progress(_S("Update Partition"), nameView.sys_str().c_str(), 0, idx / (float)nodeCount);
idx++;
};
2015-09-29 03:49:31 +00:00
update->getFSTRoot().extractToDirectory(target, ctx);
2015-09-02 22:00:40 +00:00
progress(_S("Update Partition"), _S(""), 0, 1.0);
2015-07-20 23:25:16 +00:00
}
if (!m_standalone)
{
2015-09-02 22:00:40 +00:00
progress(_S("Trilogy Files"), _S(""), 1, 0.0);
2015-10-04 05:08:56 +00:00
NOD::Partition* data = m_disc->getDataPartition();
const NOD::Node& root = data->getFSTRoot();
for (const NOD::Node& child : root)
2015-11-21 01:16:07 +00:00
if (child.getKind() == NOD::Node::Kind::File)
2015-09-29 03:49:31 +00:00
child.extractToDirectory(target, ctx);
2015-09-02 22:00:40 +00:00
progress(_S("Trilogy Files"), _S(""), 1, 1.0);
}
}
2015-08-05 21:46:07 +00:00
extractFromDisc(*m_disc, info.force, progress);
2015-07-01 23:50:39 +00:00
}
2015-09-30 06:23:40 +00:00
bool SpecBase::canCook(const HECL::ProjectPath& path)
2015-07-01 23:50:39 +00:00
{
2015-10-04 05:08:56 +00:00
if (!checkPathPrefix(path))
return false;
2015-10-01 00:40:21 +00:00
if (HECL::IsPathBlend(path))
{
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
2015-10-07 01:17:17 +00:00
if (!conn.openBlend(path))
2015-10-01 00:40:21 +00:00
return false;
2015-11-21 01:16:07 +00:00
if (conn.getBlendType() != HECL::BlenderConnection::BlendType::None)
2015-10-01 00:40:21 +00:00
return true;
}
else if (HECL::IsPathPNG(path))
{
return true;
}
else if (HECL::IsPathYAML(path))
{
FILE* fp = HECL::Fopen(path.getAbsolutePath().c_str(), _S("r"));
bool retval = validateYAMLDNAType(fp);
fclose(fp);
return retval;
}
2015-07-22 19:05:18 +00:00
return false;
2015-07-01 23:50:39 +00:00
}
void SpecBase::doCook(const HECL::ProjectPath& path, const HECL::ProjectPath& cookedPath,
bool fast, FCookProgress progress)
2015-07-01 23:50:39 +00:00
{
2015-11-10 02:07:15 +00:00
Retro::g_curSpec = this;
2015-10-04 05:08:56 +00:00
if (HECL::IsPathBlend(path))
{
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
2015-10-07 01:17:17 +00:00
if (!conn.openBlend(path))
2015-10-04 05:08:56 +00:00
return;
2015-10-07 01:17:17 +00:00
switch (conn.getBlendType())
{
2015-11-21 01:16:07 +00:00
case HECL::BlenderConnection::BlendType::Mesh:
2015-10-04 05:08:56 +00:00
{
HECL::BlenderConnection::DataStream ds = conn.beginData();
cookMesh(cookedPath, path, ds, fast, progress);
2015-10-07 01:17:17 +00:00
break;
2015-10-04 05:08:56 +00:00
}
2015-11-21 01:16:07 +00:00
case HECL::BlenderConnection::BlendType::Actor:
2015-10-07 01:17:17 +00:00
{
HECL::BlenderConnection::DataStream ds = conn.beginData();
cookActor(cookedPath, path, ds, fast, progress);
2015-10-07 01:17:17 +00:00
break;
}
2015-11-21 01:16:07 +00:00
case HECL::BlenderConnection::BlendType::Area:
2015-10-07 01:17:17 +00:00
{
HECL::BlenderConnection::DataStream ds = conn.beginData();
cookArea(cookedPath, path, ds, fast, progress);
2015-10-07 01:17:17 +00:00
break;
}
default: break;
}
}
else if (HECL::IsPathYAML(path))
{
FILE* fp = HECL::Fopen(path.getAbsolutePath().c_str(), _S("r"));
cookYAML(cookedPath, path, fp, progress);
2015-10-04 05:08:56 +00:00
}
2015-07-01 23:50:39 +00:00
}
2015-08-05 21:46:07 +00:00
bool SpecBase::canPackage(const PackagePassInfo& info)
2015-07-01 23:50:39 +00:00
{
2015-07-22 19:05:18 +00:00
return false;
2015-07-01 23:50:39 +00:00
}
2015-08-05 21:46:07 +00:00
void SpecBase::gatherDependencies(const PackagePassInfo& info,
2015-07-01 23:50:39 +00:00
std::unordered_set<HECL::ProjectPath>& implicitsOut)
{
}
2015-08-05 21:46:07 +00:00
void SpecBase::doPackage(const PackagePassInfo& info)
2015-07-01 23:50:39 +00:00
{
}
}