metaforce/DataSpec/SpecMP1.cpp

1272 lines
48 KiB
C++
Raw Normal View History

2015-07-07 03:22:44 +00:00
#include <utility>
2017-12-29 08:08:12 +00:00
#include <cstdio>
#include <cstring>
2015-07-07 03:22:44 +00:00
2015-07-01 23:50:39 +00:00
#include "SpecBase.hpp"
2015-07-17 00:01:05 +00:00
#include "DNAMP1/DNAMP1.hpp"
2015-07-01 23:50:39 +00:00
2016-09-10 04:50:00 +00:00
#include "DNAMP1/HINT.hpp"
2015-10-01 00:40:21 +00:00
#include "DNAMP1/MLVL.hpp"
#include "DNAMP1/STRG.hpp"
2017-01-31 11:21:45 +00:00
#include "DNAMP1/SCAN.hpp"
2015-10-07 01:17:17 +00:00
#include "DNAMP1/CMDL.hpp"
2017-10-17 05:51:53 +00:00
#include "DNAMP1/DCLN.hpp"
2016-08-10 02:52:00 +00:00
#include "DNAMP1/MREA.hpp"
2015-10-23 00:45:26 +00:00
#include "DNAMP1/ANCS.hpp"
2016-09-18 23:47:48 +00:00
#include "DNAMP1/AGSC.hpp"
#include "DNAMP1/CSNG.hpp"
2017-03-20 05:09:53 +00:00
#include "DNAMP1/MAPA.hpp"
2018-02-25 08:23:27 +00:00
#include "DNAMP1/PATH.hpp"
#include "DNAMP1/FRME.hpp"
2018-04-07 20:55:57 +00:00
#include "DNAMP1/AFSM.hpp"
2017-01-21 02:38:34 +00:00
#include "DNACommon/ATBL.hpp"
2016-08-17 05:40:25 +00:00
#include "DNACommon/FONT.hpp"
2016-03-28 21:38:48 +00:00
#include "DNACommon/PART.hpp"
#include "DNACommon/SWHC.hpp"
#include "DNACommon/ELSC.hpp"
#include "DNACommon/WPSC.hpp"
#include "DNACommon/CRSC.hpp"
#include "DNACommon/DPSC.hpp"
2016-04-12 11:37:07 +00:00
#include "DNACommon/DGRP.hpp"
2017-03-20 05:09:53 +00:00
#include "DNACommon/MAPU.hpp"
2021-04-10 08:42:06 +00:00
#include "DNACommon/MetaforceVersionInfo.hpp"
#include "DNACommon/Tweaks/TweakWriter.hpp"
#include "DNAMP1/Tweaks/CTweakPlayerRes.hpp"
2016-08-31 21:00:06 +00:00
#include "DNAMP1/Tweaks/CTweakGunRes.hpp"
2016-09-16 20:18:03 +00:00
#include "DNAMP1/Tweaks/CTweakSlideShow.hpp"
#include "DNAMP1/Tweaks/CTweakPlayer.hpp"
#include "DNAMP1/Tweaks/CTweakCameraBob.hpp"
#include "DNAMP1/Tweaks/CTweakGame.hpp"
2017-01-26 10:06:18 +00:00
#include "DNAMP1/Tweaks/CTweakTargeting.hpp"
#include "DNAMP1/Tweaks/CTweakAutoMapper.hpp"
#include "DNAMP1/Tweaks/CTweakGui.hpp"
#include "DNAMP1/Tweaks/CTweakPlayerControl.hpp"
#include "DNAMP1/Tweaks/CTweakBall.hpp"
#include "DNAMP1/Tweaks/CTweakParticle.hpp"
#include "DNAMP1/Tweaks/CTweakGuiColors.hpp"
#include "DNAMP1/Tweaks/CTweakPlayerGun.hpp"
#include "DNAMP1/MazeSeeds.hpp"
#include "DNAMP1/SnowForces.hpp"
2016-04-01 04:25:00 +00:00
#include "hecl/ClientProcess.hpp"
2018-03-23 21:56:17 +00:00
#include "hecl/MultiProgressPrinter.hpp"
2017-12-29 08:08:12 +00:00
#include "hecl/Blender/Connection.hpp"
#include "hecl/Blender/SDNARead.hpp"
2017-12-29 08:08:12 +00:00
#include "nod/nod.hpp"
2016-04-01 04:25:00 +00:00
2018-12-08 05:30:43 +00:00
namespace DataSpec {
2015-07-01 23:50:39 +00:00
2017-11-13 06:19:18 +00:00
using namespace std::literals;
static logvisor::Module Log("DataSpec::SpecMP1");
2016-03-04 23:04:53 +00:00
extern hecl::Database::DataSpecEntry SpecEntMP1;
2016-04-10 04:49:02 +00:00
extern hecl::Database::DataSpecEntry SpecEntMP1PC;
extern hecl::Database::DataSpecEntry SpecEntMP1ORIG;
2015-07-16 01:57:34 +00:00
struct TextureCache {
static void Generate(PAKRouter<DNAMP1::PAKBridge>& pakRouter, hecl::Database::Project& project,
const hecl::ProjectPath& pakPath) {
hecl::ProjectPath texturePath(pakPath, "texture_cache.yaml");
hecl::ProjectPath catalogPath(pakPath, "!catalog.yaml");
2020-04-11 07:53:04 +00:00
texturePath.makeDirChain(false);
if (const auto fp = hecl::FopenUnique(catalogPath.getAbsolutePath().data(), "a")) {
fmt::print(fp.get(), FMT_STRING("TextureCache: {}\n"), texturePath.getRelativePath());
}
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Level::Info, FMT_STRING("Gathering Texture metadata (this can take up to 10 seconds)..."));
std::unordered_map<UniqueID32, TXTR::Meta> metaMap;
pakRouter.enumerateResources([&](const DNAMP1::PAK::Entry* ent) {
if (ent->type == FOURCC('TXTR') && metaMap.find(ent->id) == metaMap.end()) {
PAKEntryReadStream rs = pakRouter.beginReadStreamForId(ent->id);
metaMap[ent->id] = TXTR::GetMetaData(rs);
}
return true;
});
athena::io::YAMLDocWriter yamlW("MP1TextureCache");
for (const auto& pair : metaMap) {
hecl::ProjectPath path = pakRouter.getWorking(pair.first);
auto rec = yamlW.enterSubRecord(path.getRelativePath());
pair.second.write(yamlW);
}
athena::io::FileWriter fileW(texturePath.getAbsolutePath());
yamlW.finish(&fileW);
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Level::Info, FMT_STRING("Done..."));
2019-08-09 21:55:59 +00:00
}
static void Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) {
hecl::Database::Project& project = inPath.getProject();
athena::io::YAMLDocReader r;
athena::io::FileReader fr(inPath.getAbsolutePath());
if (!fr.isOpen() || !r.parse(&fr))
return;
std::vector<std::pair<UniqueID32, TXTR::Meta>> metaPairs;
metaPairs.reserve(r.getRootNode()->m_mapChildren.size());
for (const auto& node : r.getRootNode()->m_mapChildren) {
hecl::ProjectPath projectPath(project, node.first);
auto rec = r.enterSubRecord(node.first.c_str());
TXTR::Meta meta;
meta.read(r);
metaPairs.emplace_back(projectPath.parsedHash32(), meta);
2019-08-09 21:55:59 +00:00
}
std::sort(metaPairs.begin(), metaPairs.end(),
[](const auto& a, const auto& b) -> bool { return a.first < b.first; });
2019-08-09 21:55:59 +00:00
athena::io::FileWriter w(outPath.getAbsolutePath());
w.writeUint32Big(metaPairs.size());
for (const auto& pair : metaPairs) {
pair.first.write(w);
pair.second.write(w);
}
}
};
2018-12-08 05:30:43 +00:00
struct SpecMP1 : SpecBase {
bool checkStandaloneID(const char* id) const override { return !memcmp(id, "GM8", 3); }
2018-12-08 05:30:43 +00:00
std::vector<const nod::Node*> m_nonPaks;
std::vector<DNAMP1::PAKBridge> m_paks;
std::map<std::string, DNAMP1::PAKBridge*, hecl::CaseInsensitiveCompare> m_orderedPaks;
hecl::ProjectPath m_workPath;
hecl::ProjectPath m_cookPath;
PAKRouter<DNAMP1::PAKBridge> m_pakRouter;
std::unique_ptr<uint8_t[]> m_dolBuf;
std::unordered_map<hecl::Hash, hecl::blender::Matrix4f> m_mreaPathToXF;
SpecMP1(const hecl::Database::DataSpecEntry* specEntry, hecl::Database::Project& project, bool pc)
: SpecBase(specEntry, project, pc)
, m_workPath(project.getProjectWorkingPath(), "MP1")
, m_cookPath(project.getProjectCookedPath(SpecEntMP1), "MP1")
2019-10-01 07:38:03 +00:00
, m_pakRouter(*this, m_workPath, m_cookPath) {
2020-04-15 13:42:44 +00:00
m_game = EGame::MetroidPrime1;
SpecBase::setThreadProject();
2018-12-08 05:30:43 +00:00
}
void buildPaks(nod::Node& root, const std::vector<std::string>& args, ExtractReport& rep) {
2018-12-08 05:30:43 +00:00
m_nonPaks.clear();
m_paks.clear();
for (const nod::Node& child : root) {
bool isPak = false;
auto name = child.getName();
std::string lowerName(name);
hecl::ToLower(lowerName);
2018-12-08 05:30:43 +00:00
if (name.size() > 4) {
std::string::iterator extit = lowerName.end() - 4;
2019-10-01 07:38:03 +00:00
if (std::string(extit, lowerName.end()) == ".pak") {
2018-12-08 05:30:43 +00:00
/* This is a pak */
isPak = true;
std::string lowerBase(lowerName.begin(), extit);
/* Needs filter */
bool good = true;
if (args.size()) {
good = false;
if (!lowerName.compare(0, 7, "metroid")) {
char idxChar = lowerName[7];
for (const std::string& arg : args) {
2018-12-08 05:30:43 +00:00
if (arg.size() == 1 && iswdigit(arg[0]))
if (arg[0] == idxChar)
good = true;
}
} else
good = true;
if (!good) {
for (const std::string& arg : args) {
std::string lowerArg(arg);
hecl::ToLower(lowerArg);
2018-12-08 05:30:43 +00:00
if (!lowerArg.compare(0, lowerBase.size(), lowerBase))
good = true;
}
2015-07-07 03:22:44 +00:00
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
m_paks.emplace_back(child, good);
2015-07-10 05:28:08 +00:00
}
2018-12-08 05:30:43 +00:00
}
2015-07-10 05:28:08 +00:00
2018-12-08 05:30:43 +00:00
if (!isPak)
m_nonPaks.push_back(&child);
2015-07-01 23:50:39 +00:00
}
2015-07-12 18:07:58 +00:00
2018-12-08 05:30:43 +00:00
/* Sort PAKs alphabetically */
m_orderedPaks.clear();
2020-04-15 13:42:44 +00:00
for (DNAMP1::PAKBridge& dpak : m_paks) {
2018-12-08 05:30:43 +00:00
m_orderedPaks[std::string(dpak.getName())] = &dpak;
2020-04-15 13:42:44 +00:00
}
2018-12-08 05:30:43 +00:00
/* Assemble extract report */
rep.childOpts.reserve(m_orderedPaks.size());
for (const auto& item : m_orderedPaks) {
if (!item.second->m_doExtract) {
2018-12-08 05:30:43 +00:00
continue;
}
ExtractReport& childRep = rep.childOpts.emplace_back();
childRep.name = item.first;
2018-12-08 05:30:43 +00:00
childRep.desc = item.second->getLevelString();
}
}
bool checkFromStandaloneDisc(nod::DiscBase& disc, const std::string& regstr,
const std::vector<std::string>& args, std::vector<ExtractReport>& reps) override {
2018-12-08 05:30:43 +00:00
nod::IPartition* partition = disc.getDataPartition();
m_dolBuf = partition->getDOLBuf();
2020-04-15 13:42:44 +00:00
const char* buildInfo =
static_cast<char*>(memmem(m_dolBuf.get(), partition->getDOLSize(), "MetroidBuildInfo", 16)) + 19;
2018-12-08 05:30:43 +00:00
2020-04-15 13:42:44 +00:00
if (buildInfo == nullptr)
2018-12-08 05:30:43 +00:00
return false;
m_version = std::string(buildInfo);
2018-12-08 05:30:43 +00:00
/* Root Report */
ExtractReport& rep = reps.emplace_back();
rep.name = "MP1";
rep.desc = "Metroid Prime " + regstr;
2018-12-08 05:30:43 +00:00
if (buildInfo) {
rep.desc += " (" + m_version + ")";
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
/* Iterate PAKs and build level options */
nod::Node& root = partition->getFSTRoot();
buildPaks(root, args, rep);
return true;
}
bool checkFromTrilogyDisc(nod::DiscBase& disc, const std::string& regstr,
const std::vector<std::string>& args, std::vector<ExtractReport>& reps) override {
std::vector<std::string> mp1args;
2018-12-08 05:30:43 +00:00
bool doExtract = false;
if (args.size()) {
/* Needs filter */
for (const std::string& arg : args) {
std::string lowerArg = arg;
2018-12-08 05:30:43 +00:00
hecl::ToLower(lowerArg);
if (!lowerArg.compare(0, 3, "mp1")) {
2018-12-08 05:30:43 +00:00
doExtract = true;
mp1args.reserve(args.size());
size_t slashPos = arg.find('/');
if (slashPos == std::string::npos)
slashPos = arg.find('\\');
if (slashPos != std::string::npos)
mp1args.emplace_back(std::string(arg.begin() + slashPos + 1, arg.end()));
}
2018-12-08 05:30:43 +00:00
}
} else
doExtract = true;
if (!doExtract)
return false;
nod::IPartition* partition = disc.getDataPartition();
nod::Node& root = partition->getFSTRoot();
nod::Node::DirectoryIterator dolIt = root.find("rs5mp1_p.dol");
if (dolIt == root.end()) {
dolIt = root.find("rs5mp1jpn_p.dol");
if (dolIt == root.end())
return false;
}
2015-07-12 18:07:58 +00:00
2018-12-08 05:30:43 +00:00
m_dolBuf = dolIt->getBuf();
2020-04-15 13:42:44 +00:00
const char* buildInfo = static_cast<char*>(memmem(m_dolBuf.get(), dolIt->size(), "MetroidBuildInfo", 16)) + 19;
2018-12-08 05:30:43 +00:00
/* Root Report */
ExtractReport& rep = reps.emplace_back();
rep.name = "MP1";
rep.desc = "Metroid Prime " + regstr;
2020-04-15 13:42:44 +00:00
if (buildInfo != nullptr) {
m_version = std::string(buildInfo);
rep.desc += " (" + m_version + ")";
2018-12-08 05:30:43 +00:00
}
2015-07-12 18:07:58 +00:00
2018-12-08 05:30:43 +00:00
/* Iterate PAKs and build level options */
nod::Node::DirectoryIterator mp1It = root.find("MP1");
if (mp1It == root.end()) {
mp1It = root.find("MP1JPN");
if (mp1It == root.end())
return false;
2015-07-01 23:50:39 +00:00
}
2018-12-08 05:30:43 +00:00
buildPaks(*mp1It, mp1args, rep);
2015-07-01 23:50:39 +00:00
2018-12-08 05:30:43 +00:00
return true;
}
bool extractFromDisc(nod::DiscBase& disc, bool force, const hecl::MultiProgressPrinter& progress) override {
m_project.enableDataSpecs({"MP1-PC"});
2018-12-08 05:30:43 +00:00
nod::ExtractionContext ctx = {force, nullptr};
2018-12-08 05:30:43 +00:00
m_workPath.makeDir();
2018-12-08 05:30:43 +00:00
progress.startNewLine();
progress.print("Indexing PAKs", "", 0.0);
2018-12-08 05:30:43 +00:00
m_pakRouter.build(m_paks,
[&progress](float factor) { progress.print("Indexing PAKs", "", factor); });
progress.print("Indexing PAKs", "", 1.0);
hecl::ProjectPath outPath(m_project.getProjectWorkingPath(), "out");
2018-12-08 05:30:43 +00:00
outPath.makeDir();
disc.getDataPartition()->extractSysFiles(outPath.getAbsolutePath(), ctx);
hecl::ProjectPath mp1OutPath(outPath, "files/MP1");
2018-12-08 05:30:43 +00:00
mp1OutPath.makeDirChain(true);
2015-07-16 01:57:34 +00:00
2018-12-08 05:30:43 +00:00
/* Extract non-pak files */
progress.startNewLine();
progress.print("MP1 Root", "", 0.0);
2018-12-08 05:30:43 +00:00
int prog = 0;
ctx.progressCB = [&](std::string_view name, float) {
progress.print("MP1 Root", name, prog / (float)m_nonPaks.size());
2018-12-08 05:30:43 +00:00
};
for (const nod::Node* node : m_nonPaks) {
node->extractToDirectory(mp1OutPath.getAbsolutePath(), ctx);
prog++;
}
progress.print("MP1 Root", "", 1.0);
2018-12-08 05:30:43 +00:00
/* Extract unique resources */
hecl::ClientProcess process;
progress.startNewLine();
for (std::pair<const std::string, DNAMP1::PAKBridge*>& pair : m_orderedPaks) {
#if 0
2019-08-31 20:40:07 +00:00
const DNAMP1::PAK::Entry* ent = pair.second->getPAK().lookupEntry(UniqueID32(0xE39FC9A1));
if (ent) {
PAKEntryReadStream rs = ent->beginReadStream(pair.second->getNode());
DNAMP1::CMDL::Extract(*this, rs, hecl::ProjectPath(m_project.getProjectWorkingPath(), "MP1/Metroid1/!1IntroLevel1027/CMDL_E39FC9A1.blend"), m_pakRouter, *ent, true, hecl::blender::SharedBlenderToken, {});
ent = pair.second->getPAK().lookupEntry(UniqueID32(0xC1AE2B4A));
rs = ent->beginReadStream(pair.second->getNode());
DNAMP1::CMDL::Extract(*this, rs, hecl::ProjectPath(m_project.getProjectWorkingPath(), "MP1/Metroid1/!1IntroLevel1027/CMDL_C1AE2B4A.blend"), m_pakRouter, *ent, true, hecl::blender::SharedBlenderToken, {});
exit(0);
}
else
continue;
#endif
2018-12-08 05:30:43 +00:00
DNAMP1::PAKBridge& pak = *pair.second;
if (!pak.m_doExtract)
continue;
auto pakName = std::string(pak.getName());
2018-12-08 05:30:43 +00:00
process.addLambdaTransaction([this, &progress, &pak, pakName, force](hecl::blender::Token& btok) {
int threadIdx = hecl::ClientProcess::GetThreadWorkerIdx();
m_pakRouter.extractResources(pak, force, btok,
[&progress, &pakName, threadIdx](const char* substr, float factor) {
progress.print(pakName, substr, factor, threadIdx);
2018-12-08 05:30:43 +00:00
});
});
}
2018-12-08 05:30:43 +00:00
process.waitUntilComplete();
2015-07-16 01:57:34 +00:00
2018-12-08 05:30:43 +00:00
/* Extract part of .dol for RandomStatic entropy */
hecl::ProjectPath noAramPath(m_project.getProjectWorkingPath(), "MP1/URDE");
2018-12-08 05:30:43 +00:00
extractRandomStaticEntropy(m_dolBuf.get() + 0x4f60, noAramPath);
2016-04-09 23:19:17 +00:00
/* Generate Texture Cache containing meta data for every texture file */
TextureCache::Generate(m_pakRouter, m_project, noAramPath);
2017-06-01 05:34:24 +00:00
/* Write version data */
hecl::ProjectPath versionPath = hecl::ProjectPath(m_project.getProjectWorkingPath(), "out/files/MP1");
WriteVersionInfo(m_project, versionPath);
2018-12-08 05:30:43 +00:00
return true;
}
2018-01-14 06:44:22 +00:00
const hecl::Database::DataSpecEntry& getOriginalSpec() const override { return SpecEntMP1; }
2015-10-01 00:40:21 +00:00
const hecl::Database::DataSpecEntry& getUnmodifiedSpec() const override { return SpecEntMP1ORIG; }
hecl::ProjectPath getWorking(class UniqueID32& id) override { return m_pakRouter.getWorking(id); }
bool checkPathPrefix(const hecl::ProjectPath& path) const override {
return path.getRelativePath().compare(0, 4, "MP1/") == 0;
2018-12-08 05:30:43 +00:00
}
2015-11-10 02:07:15 +00:00
bool validateYAMLDNAType(athena::io::IStreamReader& fp) const override {
2018-12-08 05:30:43 +00:00
athena::io::YAMLDocReader reader;
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)athena::io::YAMLAthenaReader, &fp);
2019-10-01 07:38:03 +00:00
return reader.ClassTypeOperation([](std::string_view classType) {
if (classType == DNAMP1::MLVL::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::STRG::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::SCAN::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAParticle::GPSM<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAParticle::SWSH<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAParticle::ELSM<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAParticle::WPSM<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAParticle::CRSM<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAParticle::DPSM<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNADGRP::DGRP<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAFont::FONT<UniqueID32>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
else if (classType == DNAMP1::CTweakPlayerRes<true>::DNAType())
return true;
else if (classType == DNAMP1::CTweakPlayerRes<false>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakGunRes::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakSlideShow::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakPlayer::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakCameraBob::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakGame::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakAutoMapper::DNAType())
2018-12-08 05:30:43 +00:00
return true;
else if (classType == DNAMP1::CTweakTargeting<true>::DNAType())
return true;
else if (classType == DNAMP1::CTweakTargeting<false>::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakGui::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakPlayerControl::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakBall::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakParticle::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakGuiColors::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::CTweakPlayerGun::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::HINT::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::EVNT::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::MazeSeeds::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::SnowForces::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == "ATBL")
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == DNAMP1::AFSM::DNAType())
2018-12-08 05:30:43 +00:00
return true;
2019-10-01 07:38:03 +00:00
else if (classType == "MP1TextureCache")
2019-08-09 21:55:59 +00:00
return true;
2018-12-08 05:30:43 +00:00
return false;
});
}
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag buildTagFromPath(const hecl::ProjectPath& path) const override {
if (hecl::StringUtils::EndsWith(path.getAuxInfo(), ".CSKR"))
2019-10-01 07:38:03 +00:00
return {SBIG('CSKR'), path.parsedHash32()};
else if (hecl::StringUtils::EndsWith(path.getAuxInfo(), ".ANIM"))
2019-10-01 07:38:03 +00:00
return {SBIG('ANIM'), path.parsedHash32()};
else if (const char* ext = path.getLastComponentExt().data()) {
if (ext[0] == '*' || !hecl::StrCmp(ext, "mid")) {
if (path.getWithExtension(".mid", true).isFile() &&
path.getWithExtension(".yaml", true).isFile()) {
hecl::ProjectPath glob = path.getWithExtension(".*", true);
2019-10-01 07:38:03 +00:00
return {SBIG('CSNG'), glob.parsedHash32()};
2018-12-08 05:30:43 +00:00
}
}
2015-10-04 05:08:56 +00:00
}
2018-12-08 05:30:43 +00:00
if (path.getPathType() == hecl::ProjectPath::Type::Directory) {
if (hecl::ProjectPath(path, "!project.yaml").isFile() &&
hecl::ProjectPath(path, "!pool.yaml").isFile())
2019-10-01 07:38:03 +00:00
return {SBIG('AGSC'), path.parsedHash32()};
2015-10-01 00:40:21 +00:00
}
2015-10-04 05:08:56 +00:00
2018-12-08 05:30:43 +00:00
hecl::ProjectPath asBlend;
if (path.getPathType() == hecl::ProjectPath::Type::Glob)
asBlend = path.getWithExtension(".blend", true);
2018-12-08 05:30:43 +00:00
else
asBlend = path;
if (hecl::IsPathBlend(asBlend)) {
switch (hecl::blender::GetBlendType(asBlend.getAbsolutePath())) {
case hecl::blender::BlendType::Mesh:
2019-10-01 07:38:03 +00:00
return {SBIG('CMDL'), path.parsedHash32()};
2018-12-08 05:30:43 +00:00
case hecl::blender::BlendType::ColMesh:
2019-10-01 07:38:03 +00:00
return {SBIG('DCLN'), path.parsedHash32()};
case hecl::blender::BlendType::Armature:
return {SBIG('CINF'), path.parsedHash32()};
2018-12-08 05:30:43 +00:00
case hecl::blender::BlendType::PathMesh:
2019-10-01 07:38:03 +00:00
return {SBIG('PATH'), path.parsedHash32()};
2018-12-08 05:30:43 +00:00
case hecl::blender::BlendType::Actor:
if (path.getAuxInfo().size()) {
if (hecl::StringUtils::EndsWith(path.getAuxInfo(), ".CSKR"))
return {SBIG('CSKR'), path.getWithExtension(".*", true).parsedHash32()};
else if (hecl::StringUtils::EndsWith(path.getAuxInfo(), ".ANIM"))
return {SBIG('ANIM'), path.getWithExtension(".*", true).parsedHash32()};
2017-01-21 02:38:34 +00:00
}
return {SBIG('ANCS'), path.getWithExtension(".*", true).parsedHash32()};
2018-12-08 05:30:43 +00:00
case hecl::blender::BlendType::Area:
2019-10-01 07:38:03 +00:00
return {SBIG('MREA'), path.parsedHash32()};
case hecl::blender::BlendType::World:
return {SBIG('MLVL'), path.getWithExtension(".*", true).parsedHash32()};
2018-12-08 05:30:43 +00:00
case hecl::blender::BlendType::MapArea:
2019-10-01 07:38:03 +00:00
return {SBIG('MAPA'), path.parsedHash32()};
2018-12-08 05:30:43 +00:00
case hecl::blender::BlendType::MapUniverse:
2019-10-01 07:38:03 +00:00
return {SBIG('MAPU'), path.parsedHash32()};
2018-12-08 05:30:43 +00:00
case hecl::blender::BlendType::Frame:
2019-10-01 07:38:03 +00:00
return {SBIG('FRME'), path.parsedHash32()};
2018-12-08 05:30:43 +00:00
default:
return {};
}
} else if (hecl::IsPathPNG(path)) {
2019-10-01 07:38:03 +00:00
return {SBIG('TXTR'), path.parsedHash32()};
2018-12-08 05:30:43 +00:00
} else if (hecl::IsPathYAML(path)) {
auto fp = hecl::FopenUnique(path.getAbsolutePath().data(), "r");
if (fp == nullptr) {
2018-12-08 05:30:43 +00:00
return {};
}
2018-12-08 05:30:43 +00:00
athena::io::YAMLDocReader reader;
yaml_parser_set_input_file(reader.getParser(), fp.get());
2016-10-02 22:41:36 +00:00
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag resTag;
2019-10-01 07:38:03 +00:00
if (reader.ClassTypeOperation([&](std::string_view className) {
if (className == DNAParticle::GPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('PART');
return true;
2016-10-02 22:41:36 +00:00
}
2019-10-01 07:38:03 +00:00
if (className == DNAParticle::SWSH<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('SWHC');
return true;
2016-10-02 22:41:36 +00:00
}
2019-10-01 07:38:03 +00:00
if (className == DNAParticle::ELSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('ELSC');
return true;
2016-10-02 22:41:36 +00:00
}
2019-10-01 07:38:03 +00:00
if (className == DNAParticle::WPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('WPSC');
return true;
}
2019-10-01 07:38:03 +00:00
if (className == DNAParticle::CRSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('CRSC');
return true;
}
2019-10-01 07:38:03 +00:00
if (className == DNAParticle::DPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('DPSC');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DNAFont::FONT<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('FONT');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DNAMP1::EVNT::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('EVNT');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DNADGRP::DGRP<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('DGRP');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DataSpec::DNAMP1::STRG::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('STRG');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DataSpec::DNAMP1::SCAN::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('SCAN');
return true;
} else if (className == DataSpec::DNAMP1::CTweakPlayerRes<true>::DNAType() ||
className == DataSpec::DNAMP1::CTweakPlayerRes<false>::DNAType() ||
2019-10-01 07:38:03 +00:00
className == DataSpec::DNAMP1::CTweakGunRes::DNAType() ||
className == DataSpec::DNAMP1::CTweakSlideShow::DNAType() ||
className == DataSpec::DNAMP1::CTweakPlayer::DNAType() ||
className == DataSpec::DNAMP1::CTweakCameraBob::DNAType() ||
className == DataSpec::DNAMP1::CTweakGame::DNAType() ||
className == DataSpec::DNAMP1::CTweakTargeting<true>::DNAType() ||
className == DataSpec::DNAMP1::CTweakTargeting<false>::DNAType() ||
2019-10-01 07:38:03 +00:00
className == DataSpec::DNAMP1::CTweakAutoMapper::DNAType() ||
className == DataSpec::DNAMP1::CTweakGui::DNAType() ||
className == DataSpec::DNAMP1::CTweakPlayerControl::DNAType() ||
className == DataSpec::DNAMP1::CTweakBall::DNAType() ||
className == DataSpec::DNAMP1::CTweakParticle::DNAType() ||
className == DataSpec::DNAMP1::CTweakGuiColors::DNAType() ||
className == DataSpec::DNAMP1::CTweakPlayerGun::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('CTWK');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DataSpec::DNAMP1::MazeSeeds::DNAType() ||
className == DataSpec::DNAMP1::SnowForces::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('DUMB');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DataSpec::DNAMP1::HINT::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('HINT');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == "ATBL") {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('ATBL');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == DataSpec::DNAMP1::AFSM::DNAType()) {
2018-12-08 05:30:43 +00:00
resTag.type = SBIG('AFSM');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == "MP1TextureCache") {
2019-08-09 21:55:59 +00:00
resTag.type = SBIG('TMET');
return true;
2019-10-01 07:38:03 +00:00
} else if (className == "DataSpec::DNAMP1::SAVW") {
resTag.type = SBIG('SAVW');
return true;
} else if (className == "DataSpec::DNAMP1::MAPW") {
resTag.type = SBIG('MAPW');
return true;
2018-04-07 20:55:57 +00:00
}
2016-08-10 02:52:00 +00:00
2018-12-08 05:30:43 +00:00
return false;
})) {
2019-10-01 07:38:03 +00:00
resTag.id = path.parsedHash32();
fp.reset();
2018-12-08 05:30:43 +00:00
return resTag;
}
}
return {};
}
2021-04-10 08:42:06 +00:00
void getTagListForFile(const char* pakName, std::vector<metaforce::SObjectTag>& out) const override {
2018-12-08 05:30:43 +00:00
std::string pathPrefix("MP1/");
pathPrefix += pakName;
pathPrefix += '/';
std::unique_lock lk(m_backgroundIndexMutex);
2018-12-08 05:30:43 +00:00
for (const auto& tag : m_tagToPath)
if (!tag.second.getRelativePath().compare(0, pathPrefix.size(), pathPrefix))
2018-12-08 05:30:43 +00:00
out.push_back(tag.first);
}
void cookMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
hecl::blender::Token& btok, FCookProgress progress) override {
Mesh mesh = ds.compileMesh(fast ? hecl::HMDLTopology::Triangles : hecl::HMDLTopology::TriStrips, m_pc ? 16 : -1);
2018-12-08 05:30:43 +00:00
if (m_pc)
DNAMP1::CMDL::HMDLCook(out, in, mesh);
else
DNAMP1::CMDL::Cook(out, in, mesh);
}
void cookColMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
hecl::blender::Token& btok, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
std::vector<ColMesh> mesh = ds.compileColMeshes();
ds.close();
DNAMP1::DCLN::Cook(out, mesh);
}
2019-10-01 07:38:03 +00:00
void cookArmature(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
hecl::blender::Token& btok, FCookProgress progress) override {
Armature armature = ds.compileArmature();
ds.close();
DNAMP1::CINF::Cook(out, in, armature);
}
2018-12-08 05:30:43 +00:00
void cookPathMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
hecl::blender::Token& btok, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
PathMesh mesh = ds.compilePathMesh();
ds.close();
2019-01-31 07:52:21 +00:00
DNAMP1::PATH::Cook(out, in, mesh, btok);
2018-12-08 05:30:43 +00:00
}
void cookActor(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
hecl::blender::Token& btok, FCookProgress progress) override {
if (hecl::StringUtils::EndsWith(in.getAuxInfo(), ".CSKR")) {
2018-12-08 05:30:43 +00:00
Actor actor = ds.compileActorCharacterOnly();
ds.close();
if (m_pc) {
DNAMP1::ANCS::CookCSKRPC(out, in, actor, [&](const hecl::ProjectPath& modelPath) {
hecl::ProjectPath cooked = modelPath.getCookedPath(SpecEntMP1PC);
doCook(modelPath, cooked, fast, btok, progress);
return true;
});
} else {
DNAMP1::ANCS::CookCSKR(out, in, actor, [&](const hecl::ProjectPath& modelPath) {
hecl::ProjectPath cooked = modelPath.getCookedPath(SpecEntMP1);
doCook(modelPath, cooked, fast, btok, progress);
return true;
});
}
} else if (hecl::StringUtils::EndsWith(in.getAuxInfo(), ".ANIM")) {
2018-12-08 05:30:43 +00:00
Actor actor = ds.compileActorCharacterOnly();
DNAMP1::ANCS::CookANIM(out, in, actor, ds, m_pc);
} else {
Actor actor = ds.compileActor();
DNAMP1::ANCS::Cook(out, in, actor);
}
}
void buildAreaXFs(hecl::blender::Token& btok) {
hecl::blender::Connection& conn = btok.getBlenderConnection();
for (const auto& ent : m_workPath.enumerateDir()) {
if (ent.m_isDir) {
hecl::ProjectPath pakPath(m_workPath, ent.m_name);
for (const auto& ent2 : pakPath.enumerateDir()) {
if (ent2.m_isDir) {
2019-10-01 07:38:03 +00:00
hecl::ProjectPath wldDir(pakPath, ent2.m_name);
for (const auto& ent3 : wldDir.enumerateDir()) {
if (hecl::StringUtils::BeginsWith(ent3.m_name, "!world") &&
hecl::StringUtils::EndsWith(ent3.m_name, ".blend")) {
2019-10-01 07:38:03 +00:00
hecl::ProjectPath wldPath(wldDir, ent3.m_name);
if (wldPath.isFile()) {
if (!conn.openBlend(wldPath))
continue;
hecl::blender::DataStream ds = conn.beginData();
hecl::blender::World world = ds.compileWorld();
for (const auto& area : world.areas)
m_mreaPathToXF[area.path.hash()] = area.transform;
}
break;
}
}
2018-12-08 05:30:43 +00:00
}
2018-02-25 08:23:27 +00:00
}
2018-12-08 05:30:43 +00:00
}
2015-10-04 05:08:56 +00:00
}
2018-12-08 05:30:43 +00:00
}
void cookArea(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
hecl::blender::Token& btok, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
std::vector<std::string> meshes = ds.getMeshList();
std::vector<Mesh> meshCompiles;
meshCompiles.reserve(meshes.size());
std::optional<ColMesh> colMesh;
2018-12-08 05:30:43 +00:00
for (const std::string& mesh : meshes) {
2019-10-01 07:38:03 +00:00
if (mesh == "CMESH") {
2018-12-08 05:30:43 +00:00
colMesh = ds.compileColMesh(mesh);
progress("Collision Mesh");
2018-12-08 05:30:43 +00:00
continue;
}
meshCompiles.push_back(
ds.compileMesh(mesh, fast ? hecl::HMDLTopology::Triangles : hecl::HMDLTopology::TriStrips, -1, !m_pc));
}
2018-12-08 05:30:43 +00:00
if (!colMesh)
Log.report(logvisor::Fatal, FMT_STRING("unable to find mesh named 'CMESH' in {}"),
in.getAbsolutePath());
2018-12-08 05:30:43 +00:00
std::vector<Light> lights = ds.compileLights();
ds.close();
if (m_mreaPathToXF.empty())
buildAreaXFs(btok);
const hecl::blender::Matrix4f* xf = nullptr;
auto xfSearch = m_mreaPathToXF.find(in.getParentPath().hash());
if (xfSearch != m_mreaPathToXF.cend())
xf = &xfSearch->second;
DNAMP1::MREA::Cook(out, in, meshCompiles, *colMesh, lights, btok, xf, m_pc);
}
void cookWorld(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,
hecl::blender::Token& btok, FCookProgress progress) override {
2019-10-01 07:38:03 +00:00
hecl::blender::World world = ds.compileWorld();
ds.close();
DNAMP1::MLVL::Cook(out, in, world, btok);
2018-12-08 05:30:43 +00:00
}
void cookGuiFrame(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds,
hecl::blender::Token& btok, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
auto data = ds.compileGuiFrame(0);
athena::io::MemoryReader r(data.data(), data.size());
DNAMP1::FRME frme;
frme.read(r);
athena::io::FileWriter w(out.getAbsolutePath());
frme.write(w);
}
void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in, athena::io::IStreamReader& fin,
2019-10-01 07:38:03 +00:00
hecl::blender::Token& btok, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
athena::io::YAMLDocReader reader;
if (reader.parse(&fin)) {
std::string classStr = reader.readString("DNAType");
if (classStr.empty())
return;
2019-10-01 07:38:03 +00:00
if (classStr == DNAMP1::STRG::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::STRG strg;
strg.read(reader);
DNAMP1::STRG::Cook(strg, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::SCAN::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::SCAN scan;
scan.read(reader);
DNAMP1::SCAN::Cook(scan, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::GPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::GPSM<UniqueID32> gpsm;
gpsm.read(reader);
DNAParticle::WriteGPSM(gpsm, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::SWSH<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::SWSH<UniqueID32> swsh;
swsh.read(reader);
DNAParticle::WriteSWSH(swsh, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::ELSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::ELSM<UniqueID32> elsm;
elsm.read(reader);
DNAParticle::WriteELSM(elsm, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::WPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::WPSM<UniqueID32> wpsm;
wpsm.read(reader);
DNAParticle::WriteWPSM(wpsm, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::CRSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::CRSM<UniqueID32> crsm;
crsm.read(reader);
DNAParticle::WriteCRSM(crsm, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::DPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::DPSM<UniqueID32> dpsm;
dpsm.read(reader);
DNAParticle::WriteDPSM(dpsm, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNADGRP::DGRP<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNADGRP::DGRP<UniqueID32> dgrp;
dgrp.read(reader);
dgrp.validateDeps();
DNADGRP::WriteDGRP(dgrp, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAFont::FONT<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAFont::FONT<UniqueID32> font;
font.read(reader);
DNAFont::WriteFONT(font, out);
} else if (classStr == DNAMP1::CTweakPlayerRes<true>::DNAType()) {
DNAMP1::CTweakPlayerRes<true> playerRes;
playerRes.read(reader);
WriteTweak(playerRes, out);
} else if (classStr == DNAMP1::CTweakPlayerRes<false>::DNAType()) {
DNAMP1::CTweakPlayerRes<false> playerRes;
2018-12-08 05:30:43 +00:00
playerRes.read(reader);
WriteTweak(playerRes, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakGunRes::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakGunRes gunRes;
gunRes.read(reader);
WriteTweak(gunRes, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakSlideShow::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakSlideShow slideShow;
slideShow.read(reader);
WriteTweak(slideShow, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakPlayer::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakPlayer player;
player.read(reader);
WriteTweak(player, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakCameraBob::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakCameraBob cBob;
cBob.read(reader);
WriteTweak(cBob, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakGame::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakGame cGame;
cGame.read(reader);
WriteTweak(cGame, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakAutoMapper::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakAutoMapper autoMapper;
autoMapper.read(reader);
WriteTweak(autoMapper, out);
} else if (classStr == DNAMP1::CTweakTargeting<true>::DNAType()) {
DNAMP1::CTweakTargeting<false> targeting;
targeting.read(reader);
WriteTweak(targeting, out);
} else if (classStr == DNAMP1::CTweakTargeting<false>::DNAType()) {
DNAMP1::CTweakTargeting<false> targeting;
2018-12-08 05:30:43 +00:00
targeting.read(reader);
WriteTweak(targeting, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakGui::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakGui gui;
gui.read(reader);
WriteTweak(gui, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakPlayerControl::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakPlayerControl pc;
pc.read(reader);
WriteTweak(pc, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakBall::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakBall ball;
ball.read(reader);
WriteTweak(ball, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakParticle::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakParticle part;
part.read(reader);
WriteTweak(part, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakGuiColors::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakGuiColors gColors;
gColors.read(reader);
WriteTweak(gColors, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakPlayerGun::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakPlayerGun pGun;
pGun.read(reader);
WriteTweak(pGun, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::CTweakPlayerControl::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::CTweakPlayerControl pControl;
pControl.read(reader);
WriteTweak(pControl, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::MazeSeeds::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::MazeSeeds mSeeds;
mSeeds.read(reader);
WriteTweak(mSeeds, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::SnowForces::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::SnowForces sForces;
sForces.read(reader);
WriteTweak(sForces, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::HINT::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::HINT::Cook(in, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::EVNT::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::EVNT::Cook(in, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == "ATBL") {
2018-12-08 05:30:43 +00:00
DNAAudio::ATBL::Cook(in, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::AFSM::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::AFSM::Cook(in, out);
2019-10-01 07:38:03 +00:00
} else if (classStr == "MP1TextureCache") {
2019-08-09 21:55:59 +00:00
TextureCache::Cook(in, out);
2018-12-08 05:30:43 +00:00
}
2015-10-04 05:08:56 +00:00
}
progress("Done");
2018-12-08 05:30:43 +00:00
}
void flattenDependenciesYAML(athena::io::IStreamReader& fin, std::vector<hecl::ProjectPath>& pathsOut) override {
2018-12-08 05:30:43 +00:00
athena::io::YAMLDocReader reader;
if (reader.parse(&fin)) {
2019-10-01 07:38:03 +00:00
std::string classStr = reader.readString("DNAType"sv);
2018-12-08 05:30:43 +00:00
if (classStr.empty())
return;
2019-10-01 07:38:03 +00:00
if (classStr == DNAMP1::STRG::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::STRG strg;
strg.read(reader);
strg.gatherDependencies(pathsOut);
}
2019-10-01 07:38:03 +00:00
if (classStr == DNAMP1::SCAN::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::SCAN scan;
scan.read(reader);
scan.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::GPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::GPSM<UniqueID32> gpsm;
gpsm.read(reader);
gpsm.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::SWSH<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::SWSH<UniqueID32> swsh;
swsh.read(reader);
swsh.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::ELSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::ELSM<UniqueID32> elsm;
elsm.read(reader);
elsm.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::WPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::WPSM<UniqueID32> wpsm;
wpsm.read(reader);
wpsm.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::CRSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::CRSM<UniqueID32> crsm;
crsm.read(reader);
crsm.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAParticle::DPSM<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAParticle::DPSM<UniqueID32> dpsm;
dpsm.read(reader);
dpsm.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAFont::FONT<UniqueID32>::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAFont::FONT<UniqueID32> font;
font.read(reader);
font.gatherDependencies(pathsOut);
2019-10-01 07:38:03 +00:00
} else if (classStr == DNAMP1::EVNT::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::EVNT evnt;
evnt.read(reader);
evnt.gatherDependencies(pathsOut);
}
2016-10-02 22:41:36 +00:00
}
2018-12-08 05:30:43 +00:00
}
void flattenDependenciesANCSYAML(athena::io::IStreamReader& fin, std::vector<hecl::ProjectPath>& pathsOut,
int charIdx) override {
2018-12-08 05:30:43 +00:00
athena::io::YAMLDocReader reader;
if (reader.parse(&fin)) {
std::string classStr = reader.readString("DNAType");
2019-10-01 07:38:03 +00:00
if (classStr == DNAMP1::ANCS::DNAType()) {
2018-12-08 05:30:43 +00:00
DNAMP1::ANCS ancs;
ancs.read(reader);
ancs.gatherDependencies(pathsOut, charIdx);
}
2017-11-15 04:12:13 +00:00
}
2018-12-08 05:30:43 +00:00
}
void buildWorldPakList(const hecl::ProjectPath& worldPath, const hecl::ProjectPath& worldPathCooked,
2021-06-07 19:29:18 +00:00
hecl::blender::Token& btok, athena::io::FileWriter& w,
std::vector<metaforce::SObjectTag>& listOut, atUint64& resTableOffset,
2021-04-10 08:42:06 +00:00
std::unordered_map<metaforce::CAssetId, std::vector<uint8_t>>& mlvlData) override {
2018-12-08 05:30:43 +00:00
DNAMP1::MLVL mlvl;
{
2018-12-08 05:30:43 +00:00
athena::io::FileReader r(worldPathCooked.getAbsolutePath());
if (r.hasError())
Log.report(logvisor::Fatal, FMT_STRING("Unable to open world {}"), worldPathCooked.getRelativePath());
2018-12-08 05:30:43 +00:00
mlvl.read(r);
}
2018-12-08 05:30:43 +00:00
size_t count = 5;
for (const auto& area : mlvl.areas) {
auto lazyIt = area.lazyDeps.cbegin();
auto it = area.deps.cbegin();
while (it != area.deps.cend()) {
if (it->id != lazyIt->id)
++count;
++lazyIt;
++it;
}
}
2018-12-08 05:30:43 +00:00
listOut.reserve(count);
metaforce::SObjectTag worldTag = tagFromPath(worldPath.getWithExtension(".*", true));
2018-12-08 05:30:43 +00:00
w.writeUint32Big(m_pc ? 0x80030005 : 0x00030005);
w.writeUint32Big(0);
w.writeUint32Big(1);
DNAMP1::PAK::NameEntry nameEnt;
hecl::ProjectPath parentDir = worldPath.getParentPath();
nameEnt.type = worldTag.type;
2019-10-01 07:38:03 +00:00
nameEnt.id = worldTag.id.Value();
2018-12-08 05:30:43 +00:00
nameEnt.nameLen = atUint32(parentDir.getLastComponent().size());
nameEnt.name = parentDir.getLastComponent();
2018-12-08 05:30:43 +00:00
nameEnt.write(w);
2021-04-10 08:42:06 +00:00
std::unordered_set<metaforce::CAssetId> addedTags;
2018-12-08 05:30:43 +00:00
for (auto& area : mlvl.areas) {
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag areaTag(FOURCC('MREA'), area.areaMREAId.toUint64());
2018-12-08 05:30:43 +00:00
bool dupeRes = false;
if (hecl::ProjectPath areaDir = pathFromTag(areaTag).getParentPath())
dupeRes = hecl::ProjectPath(areaDir, "!duperes").isFile();
2018-12-08 05:30:43 +00:00
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag nameTag(FOURCC('STRG'), area.areaNameId.toUint64());
2018-12-08 05:30:43 +00:00
if (nameTag)
listOut.push_back(nameTag);
for (const auto& dep : area.deps) {
2021-04-10 08:42:06 +00:00
metaforce::CAssetId newId = dep.id.toUint64();
2018-12-08 05:30:43 +00:00
if (dupeRes || addedTags.find(newId) == addedTags.end()) {
listOut.emplace_back(dep.type, newId);
2018-12-08 05:30:43 +00:00
addedTags.insert(newId);
}
2018-12-08 05:30:43 +00:00
}
if (areaTag)
listOut.push_back(areaTag);
std::vector<DNAMP1::MLVL::Area::Dependency> strippedDeps;
strippedDeps.reserve(area.deps.size());
std::vector<atUint32> strippedDepLayers;
strippedDepLayers.reserve(area.depLayers.size());
auto lazyIt = area.lazyDeps.cbegin();
auto it = area.deps.cbegin();
auto layerIt = area.depLayers.cbegin();
while (it != area.deps.cend()) {
while (layerIt != area.depLayers.cend() && it - area.deps.cbegin() == *layerIt) {
strippedDepLayers.push_back(atUint32(strippedDeps.size()));
++layerIt;
2018-04-02 04:27:24 +00:00
}
2018-12-08 05:30:43 +00:00
if (it->id != lazyIt->id)
strippedDeps.push_back(*it);
++lazyIt;
++it;
}
area.lazyDepCount = 0;
area.lazyDeps.clear();
area.depCount = strippedDeps.size();
area.deps = std::move(strippedDeps);
area.depLayerCount = strippedDepLayers.size();
area.depLayers = std::move(strippedDepLayers);
}
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag nameTag(FOURCC('STRG'), mlvl.worldNameId.toUint64());
2018-12-08 05:30:43 +00:00
if (nameTag)
listOut.push_back(nameTag);
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag savwTag(FOURCC('SAVW'), mlvl.saveWorldId.toUint64());
2018-12-08 05:30:43 +00:00
if (savwTag) {
if (hecl::ProjectPath savwPath = pathFromTag(savwTag))
m_project.cookPath(savwPath, {}, false, true);
listOut.push_back(savwTag);
}
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag mapTag(FOURCC('MAPW'), mlvl.worldMap.toUint64());
2018-12-08 05:30:43 +00:00
if (mapTag) {
if (hecl::ProjectPath mapPath = pathFromTag(mapTag)) {
m_project.cookPath(mapPath, {}, false, true);
if (hecl::ProjectPath mapCookedPath = getCookedPath(mapPath, true)) {
athena::io::FileReader r(mapCookedPath.getAbsolutePath());
if (r.hasError())
Log.report(logvisor::Fatal, FMT_STRING("Unable to open {}"), mapCookedPath.getRelativePath());
2018-12-08 05:30:43 +00:00
if (r.readUint32Big() != 0xDEADF00D)
Log.report(logvisor::Fatal, FMT_STRING("Corrupt MAPW {}"), mapCookedPath.getRelativePath());
2018-12-08 05:30:43 +00:00
r.readUint32Big();
atUint32 mapaCount = r.readUint32Big();
for (atUint32 i = 0; i < mapaCount; ++i) {
2018-12-08 05:30:43 +00:00
UniqueID32 id;
id.read(r);
listOut.emplace_back(FOURCC('MAPA'), id.toUint64());
2018-12-08 05:30:43 +00:00
}
}
2018-12-08 05:30:43 +00:00
}
listOut.push_back(mapTag);
}
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag skyboxTag(FOURCC('CMDL'), mlvl.worldSkyboxId.toUint64());
2018-12-08 05:30:43 +00:00
if (skyboxTag) {
listOut.push_back(skyboxTag);
hecl::ProjectPath skyboxPath = pathFromTag(skyboxTag);
if (btok.getBlenderConnection().openBlend(skyboxPath)) {
auto data = btok.getBlenderConnection().beginData();
std::vector<hecl::ProjectPath> textures = data.getTextures();
for (const auto& tex : textures) {
2021-04-10 08:42:06 +00:00
metaforce::SObjectTag texTag = tagFromPath(tex);
2018-12-08 05:30:43 +00:00
if (!texTag)
Log.report(logvisor::Fatal, FMT_STRING("Unable to resolve {}"), tex.getRelativePath());
2018-12-08 05:30:43 +00:00
listOut.push_back(texTag);
}
2018-12-08 05:30:43 +00:00
}
2016-09-18 23:47:48 +00:00
}
2018-12-08 05:30:43 +00:00
listOut.push_back(worldTag);
w.writeUint32Big(atUint32(listOut.size()));
resTableOffset = w.position();
for (const auto& item : listOut) {
DNAMP1::PAK::Entry ent;
ent.compressed = 0;
ent.type = item.type;
2019-10-01 07:38:03 +00:00
ent.id = item.id.Value();
2018-12-08 05:30:43 +00:00
ent.size = 0;
ent.offset = 0;
ent.write(w);
2016-09-18 23:47:48 +00:00
}
2017-03-20 05:09:53 +00:00
{
2018-12-08 05:30:43 +00:00
std::vector<uint8_t>& mlvlOut = mlvlData[worldTag.id];
size_t mlvlSize = 0;
mlvl.binarySize(mlvlSize);
mlvlOut.resize(mlvlSize);
2019-10-01 07:38:03 +00:00
athena::io::MemoryWriter mw(&mlvlOut[0], mlvlSize);
mlvl.write(mw);
2018-12-08 05:30:43 +00:00
}
}
2021-06-07 19:29:18 +00:00
void buildPakList(hecl::blender::Token& btok, athena::io::FileWriter& w,
const std::vector<metaforce::SObjectTag>& list,
2021-04-10 08:42:06 +00:00
const std::vector<std::pair<metaforce::SObjectTag, std::string>>& nameList,
atUint64& resTableOffset) override {
2018-12-08 05:30:43 +00:00
w.writeUint32Big(m_pc ? 0x80030005 : 0x00030005);
w.writeUint32Big(0);
w.writeUint32Big(atUint32(nameList.size()));
for (const auto& item : nameList) {
DNAMP1::PAK::NameEntry nameEnt;
nameEnt.type = item.first.type;
2019-10-01 07:38:03 +00:00
nameEnt.id = item.first.id.Value();
2018-12-08 05:30:43 +00:00
nameEnt.nameLen = atUint32(item.second.size());
nameEnt.name = item.second;
nameEnt.write(w);
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
w.writeUint32Big(atUint32(list.size()));
resTableOffset = w.position();
for (const auto& item : list) {
DNAMP1::PAK::Entry ent;
ent.compressed = 0;
ent.type = item.type;
2019-10-01 07:38:03 +00:00
ent.id = item.id.Value();
2018-12-08 05:30:43 +00:00
ent.size = 0;
ent.offset = 0;
ent.write(w);
}
}
2021-04-10 08:42:06 +00:00
void writePakFileIndex(athena::io::FileWriter& w, const std::vector<metaforce::SObjectTag>& tags,
const std::vector<std::tuple<size_t, size_t, bool>>& index, atUint64 resTableOffset) override {
w.seek(resTableOffset, athena::SeekOrigin::Begin);
2018-12-08 05:30:43 +00:00
auto it = tags.begin();
for (const auto& item : index) {
2021-04-10 08:42:06 +00:00
const metaforce::SObjectTag& tag = *it++;
2018-12-08 05:30:43 +00:00
DNAMP1::PAK::Entry ent;
ent.compressed = atUint32(std::get<2>(item));
ent.type = tag.type;
2019-10-01 07:38:03 +00:00
ent.id = tag.id.Value();
2018-12-08 05:30:43 +00:00
ent.size = atUint32(std::get<1>(item));
ent.offset = atUint32(std::get<0>(item));
ent.write(w);
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
}
2021-04-10 08:42:06 +00:00
std::pair<std::unique_ptr<uint8_t[]>, size_t> compressPakData(const metaforce::SObjectTag& tag, const uint8_t* data,
size_t len) override {
2018-12-08 05:30:43 +00:00
bool doCompress = false;
2019-07-20 04:27:21 +00:00
switch (tag.type.toUint32()) {
2018-12-08 05:30:43 +00:00
case SBIG('TXTR'):
case SBIG('CMDL'):
case SBIG('CSKR'):
case SBIG('ANCS'):
case SBIG('ANIM'):
case SBIG('FONT'):
doCompress = true;
break;
case SBIG('PART'):
case SBIG('ELSC'):
case SBIG('SWHC'):
case SBIG('WPSC'):
case SBIG('DPSC'):
case SBIG('CRSC'):
doCompress = len >= 0x400;
break;
default:
break;
}
if (!doCompress)
return {};
uLong destLen = compressBound(len);
std::pair<std::unique_ptr<uint8_t[]>, size_t> ret;
ret.first.reset(new uint8_t[destLen]);
compress2(ret.first.get(), &destLen, data, len, Z_BEST_COMPRESSION);
ret.second = destLen;
return ret;
};
void cookAudioGroup(const hecl::ProjectPath& out, const hecl::ProjectPath& in, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
DNAMP1::AGSC::Cook(in, out);
progress("Done");
2018-12-08 05:30:43 +00:00
}
void cookSong(const hecl::ProjectPath& out, const hecl::ProjectPath& in, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
DNAMP1::CSNG::Cook(in, out);
progress("Done");
2018-12-08 05:30:43 +00:00
}
void cookMapArea(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds,
hecl::blender::Token& btok, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
hecl::blender::MapArea mapa = ds.compileMapArea();
ds.close();
DNAMP1::MAPA::Cook(mapa, out);
progress("Done");
2018-12-08 05:30:43 +00:00
}
void cookMapUniverse(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds,
hecl::blender::Token& btok, FCookProgress progress) override {
2018-12-08 05:30:43 +00:00
hecl::blender::MapUniverse mapu = ds.compileMapUniverse();
ds.close();
DNAMAPU::MAPU::Cook(mapu, out);
progress("Done");
2018-12-08 05:30:43 +00:00
}
2015-07-01 23:50:39 +00:00
};
2017-01-31 11:21:45 +00:00
hecl::Database::DataSpecEntry SpecEntMP1 = {
"MP1"sv, "Data specification for original Metroid Prime engine"sv, ".pak"sv,
[](hecl::Database::Project& project, hecl::Database::DataSpecTool) -> std::unique_ptr<hecl::Database::IDataSpec> {
2018-12-08 05:30:43 +00:00
return std::make_unique<SpecMP1>(&SpecEntMP1, project, false);
2017-01-31 11:21:45 +00:00
}};
2015-07-01 23:50:39 +00:00
2017-01-31 11:21:45 +00:00
hecl::Database::DataSpecEntry SpecEntMP1PC = {
"MP1-PC"sv, "Data specification for PC-optimized Metroid Prime engine"sv, ".upak"sv,
2018-12-08 05:30:43 +00:00
[](hecl::Database::Project& project,
hecl::Database::DataSpecTool tool) -> std::unique_ptr<hecl::Database::IDataSpec> {
if (tool != hecl::Database::DataSpecTool::Extract)
return std::make_unique<SpecMP1>(&SpecEntMP1PC, project, true);
return {};
2017-01-31 11:21:45 +00:00
}};
2017-01-31 11:21:45 +00:00
hecl::Database::DataSpecEntry SpecEntMP1ORIG = {
"MP1-ORIG"sv, "Data specification for unmodified Metroid Prime resources"sv, {}, {}};
2018-12-08 05:30:43 +00:00
} // namespace DataSpec