2015-11-27 22:21:19 +00:00
|
|
|
#if _WIN32
|
|
|
|
#define _CRT_RAND_S
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2015-07-01 23:50:39 +00:00
|
|
|
#include "SpecBase.hpp"
|
2015-08-04 21:35:41 +00:00
|
|
|
#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
|
|
|
|
2015-11-22 05:16:40 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
namespace DataSpec
|
2015-07-01 23:50:39 +00:00
|
|
|
{
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
static logvisor::Module Log("urde::SpecBase");
|
2015-08-04 21:35:41 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
static const hecl::SystemChar* MomErr[] =
|
2015-11-22 05:16:40 +00:00
|
|
|
{
|
|
|
|
_S("Your metroid is in another castle"),
|
|
|
|
_S("HECL is experiencing a PTSD attack"),
|
|
|
|
_S("Unable to freeze metroids"),
|
|
|
|
_S("Ridley ate your homework"),
|
|
|
|
_S("Expected 0 maternal symbolisms, found ∞"),
|
|
|
|
_S("Contradictive narratives unsupported"),
|
|
|
|
_S("Wiimote profile \"NES + Zapper\" not recognized"),
|
|
|
|
_S("Unable to find Waldo"),
|
2016-02-20 08:53:06 +00:00
|
|
|
_S("Expected Ridley, found furby"),
|
|
|
|
_S("Adam has not authorized this, please do not bug the developers"),
|
|
|
|
_S("Error: Lady returned objection")
|
2015-11-22 05:16:40 +00:00
|
|
|
};
|
|
|
|
|
2016-02-20 08:53:06 +00:00
|
|
|
constexpr uint32_t MomErrCount = 11;
|
2016-03-04 23:04:53 +00:00
|
|
|
SpecBase::SpecBase(hecl::Database::Project& project)
|
2015-11-10 02:07:15 +00:00
|
|
|
: 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
|
|
|
{
|
2016-03-04 23:04:53 +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;
|
2016-01-20 03:18:30 +00:00
|
|
|
const char* gameID = m_disc->getHeader().m_gameID;
|
2015-07-02 20:41:40 +00:00
|
|
|
|
2015-11-22 05:16:40 +00:00
|
|
|
if (!memcmp(gameID, "R3O", 3))
|
|
|
|
{
|
|
|
|
unsigned int t = time(nullptr);
|
2015-11-27 22:21:19 +00:00
|
|
|
#if _WIN32
|
|
|
|
rand_s(&t);
|
2016-02-20 08:53:06 +00:00
|
|
|
int r = t % MomErrCount;
|
2015-11-27 22:21:19 +00:00
|
|
|
#else
|
2016-02-20 08:53:06 +00:00
|
|
|
int r = rand_r(&t) % MomErrCount;
|
2015-11-27 22:21:19 +00:00
|
|
|
#endif
|
2016-03-04 23:04:53 +00:00
|
|
|
Log.report(logvisor::Fatal, MomErr[r]);
|
2015-11-22 05:16:40 +00:00
|
|
|
}
|
|
|
|
|
2015-07-18 04:33:38 +00:00
|
|
|
m_standalone = true;
|
|
|
|
if (m_isWii && !memcmp(gameID, "R3M", 3))
|
|
|
|
m_standalone = false;
|
2015-07-01 23:50:39 +00:00
|
|
|
|
2015-07-18 04:33:38 +00:00
|
|
|
if (m_standalone && !checkStandaloneID(gameID))
|
2015-07-10 05:28:08 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-20 03:18:30 +00:00
|
|
|
char region = m_disc->getHeader().m_gameID[3];
|
2016-03-04 23:04:53 +00:00
|
|
|
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 = ®NONE;
|
2015-07-12 18:07:58 +00:00
|
|
|
switch (region)
|
|
|
|
{
|
|
|
|
case 'E':
|
|
|
|
regstr = ®E;
|
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
regstr = ®J;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
regstr = ®P;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-18 04:33:38 +00:00
|
|
|
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
|
|
|
{
|
2016-02-13 09:02:47 +00:00
|
|
|
DataSpec::g_curSpec = this;
|
2015-08-05 21:46:07 +00:00
|
|
|
if (!Blender::BuildMasterShader(m_masterShader))
|
2016-03-04 23:04:53 +00:00
|
|
|
Log.report(logvisor::Fatal, "Unable to build master shader blend");
|
2015-07-18 04:33:38 +00:00
|
|
|
if (m_isWii)
|
|
|
|
{
|
2016-03-01 20:29:18 +00:00
|
|
|
/* Extract root files for repacking later */
|
2016-03-05 00:03:41 +00:00
|
|
|
hecl::ProjectPath outDir(m_project.getProjectWorkingPath(), _S("out"));
|
2016-03-01 20:29:18 +00:00
|
|
|
outDir.makeDir();
|
2016-03-04 23:04:53 +00:00
|
|
|
nod::ExtractionContext ctx = {true, info.force, nullptr};
|
2015-09-29 03:49:31 +00:00
|
|
|
|
2015-07-18 04:33:38 +00:00
|
|
|
if (!m_standalone)
|
|
|
|
{
|
2015-09-02 22:00:40 +00:00
|
|
|
progress(_S("Trilogy Files"), _S(""), 1, 0.0);
|
2016-03-04 23:04:53 +00:00
|
|
|
nod::Partition* data = m_disc->getDataPartition();
|
|
|
|
const nod::Node& root = data->getFSTRoot();
|
|
|
|
for (const nod::Node& child : root)
|
|
|
|
if (child.getKind() == nod::Node::Kind::File)
|
2016-03-01 20:29:18 +00:00
|
|
|
child.extractToDirectory(outDir.getAbsolutePath(), ctx);
|
2015-09-02 22:00:40 +00:00
|
|
|
progress(_S("Trilogy Files"), _S(""), 1, 1.0);
|
2015-07-18 04:33:38 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-05 21:46:07 +00:00
|
|
|
extractFromDisc(*m_disc, info.force, progress);
|
2015-07-01 23:50:39 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +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;
|
2016-03-04 23:04:53 +00:00
|
|
|
if (hecl::IsPathBlend(path))
|
2015-10-01 00:40:21 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
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;
|
2016-03-04 23:04:53 +00:00
|
|
|
if (conn.getBlendType() != hecl::BlenderConnection::BlendType::None)
|
2015-10-01 00:40:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
else if (hecl::IsPathPNG(path))
|
2015-10-01 00:40:21 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
else if (hecl::IsPathYAML(path))
|
2015-10-01 00:40:21 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
FILE* fp = hecl::Fopen(path.getAbsolutePath().c_str(), _S("r"));
|
2015-10-01 00:40:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
void SpecBase::doCook(const hecl::ProjectPath& path, const hecl::ProjectPath& cookedPath,
|
2015-10-22 02:03:26 +00:00
|
|
|
bool fast, FCookProgress progress)
|
2015-07-01 23:50:39 +00:00
|
|
|
{
|
2016-02-13 09:02:47 +00:00
|
|
|
DataSpec::g_curSpec = this;
|
2016-03-04 23:04:53 +00:00
|
|
|
if (hecl::IsPathBlend(path))
|
2015-10-04 05:08:56 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
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())
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
case hecl::BlenderConnection::BlendType::Mesh:
|
2015-10-04 05:08:56 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::BlenderConnection::DataStream ds = conn.beginData();
|
2015-10-22 02:03:26 +00:00
|
|
|
cookMesh(cookedPath, path, ds, fast, progress);
|
2015-10-07 01:17:17 +00:00
|
|
|
break;
|
2015-10-04 05:08:56 +00:00
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
case hecl::BlenderConnection::BlendType::Actor:
|
2015-10-07 01:17:17 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::BlenderConnection::DataStream ds = conn.beginData();
|
2015-10-22 02:03:26 +00:00
|
|
|
cookActor(cookedPath, path, ds, fast, progress);
|
2015-10-07 01:17:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
case hecl::BlenderConnection::BlendType::Area:
|
2015-10-07 01:17:17 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::BlenderConnection::DataStream ds = conn.beginData();
|
2015-10-22 02:03:26 +00:00
|
|
|
cookArea(cookedPath, path, ds, fast, progress);
|
2015-10-07 01:17:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
else if (hecl::IsPathYAML(path))
|
2015-10-07 01:17:17 +00:00
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
FILE* fp = hecl::Fopen(path.getAbsolutePath().c_str(), _S("r"));
|
2015-10-22 02:03:26 +00:00
|
|
|
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,
|
2016-03-04 23:04:53 +00:00
|
|
|
std::unordered_set<hecl::ProjectPath>& implicitsOut)
|
2015-07-01 23:50:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-08-05 21:46:07 +00:00
|
|
|
void SpecBase::doPackage(const PackagePassInfo& info)
|
2015-07-01 23:50:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|