2022-03-21 21:53:51 -04:00
|
|
|
#include "extractor.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "impl.h"
|
|
|
|
#include "utils/mutils.h"
|
2022-03-21 23:38:16 -04:00
|
|
|
#include "ctpl/ctpl_stl.h"
|
2022-03-21 21:53:51 -04:00
|
|
|
#include <thread>
|
2022-03-31 19:42:44 -04:00
|
|
|
#include <impl/baserom_extractor/baserom_extractor.h>
|
2022-03-21 21:53:51 -04:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define PLATFORM Platforms::WINDOWS
|
|
|
|
#else
|
|
|
|
#define PLATFORM Platforms::LINUX
|
|
|
|
#endif
|
|
|
|
namespace Util = MoonUtils;
|
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
bool oldExtractMode = false;
|
2022-03-21 21:53:51 -04:00
|
|
|
static int maxResources = 0;
|
|
|
|
static int extractedResources = 0;
|
|
|
|
bool buildingOtr = false;
|
|
|
|
int skipFrames = 0;
|
|
|
|
|
|
|
|
bool isWindows() {
|
|
|
|
return (PLATFORM == Platforms::WINDOWS);
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
std::string GetXMLVersion(RomVersion version)
|
|
|
|
{
|
|
|
|
switch (version.crc)
|
|
|
|
{
|
|
|
|
case OOT_PAL_GC_DBG1: return "GC_NMQ_D";
|
2022-09-21 00:38:54 -04:00
|
|
|
case OOT_PAL_GC_MQ_DBG: return "GC_MQ_D";
|
2022-03-31 19:42:44 -04:00
|
|
|
case OOT_PAL_GC: return "GC_NMQ_PAL_F";
|
|
|
|
}
|
2022-03-21 21:53:51 -04:00
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
return "ERROR";
|
|
|
|
}
|
2022-03-21 21:53:51 -04:00
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
void BuildOTR(const std::string output) {
|
|
|
|
if (oldExtractMode)
|
|
|
|
{
|
|
|
|
std::string execStr = Util::format("assets/extractor/%s", isWindows() ? "ZAPD.exe" : "ZAPD.out") + " botr -se OTR";
|
|
|
|
ProcessResult result = NativeFS->LaunchProcess(execStr);
|
|
|
|
if (result.exitCode != 0) {
|
|
|
|
std::cout << "\nError when building the OTR file with error code: " << result.exitCode << " !" << std::endl;
|
|
|
|
std::cout << "Aborting...\n" << std::endl;
|
|
|
|
}
|
2022-03-21 21:53:51 -04:00
|
|
|
}
|
2022-03-31 19:42:44 -04:00
|
|
|
|
2022-03-21 21:53:51 -04:00
|
|
|
setCurrentStep("Done!");
|
|
|
|
|
|
|
|
if (output == ".") return;
|
|
|
|
const std::string outputPath = MoonUtils::join(output, "oot.otr");
|
|
|
|
if(MoonUtils::exists(outputPath)) MoonUtils::rm(outputPath);
|
|
|
|
|
|
|
|
MoonUtils::copy("oot.otr", outputPath);
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
void ExtractFile(std::string xmlPath, std::string outPath, std::string outSrcPath, RomVersion version) {
|
2022-03-21 21:53:51 -04:00
|
|
|
std::string execStr = Util::format("assets/extractor/%s", isWindows() ? "ZAPD.exe" : "ZAPD.out");
|
2022-03-31 19:42:44 -04:00
|
|
|
std::string args = Util::format(" e -eh -i %s -b tmp/baserom/ -o %s -osf %s -gsf 1 -rconf assets/extractor/Config_%s.xml -se OTR %s", xmlPath.c_str(), outPath.c_str(), outSrcPath.c_str(), GetXMLVersion(version).c_str(), xmlPath.find("overlays") != std::string::npos ? "--static" : "");
|
2022-03-21 21:53:51 -04:00
|
|
|
ProcessResult result = NativeFS->LaunchProcess(execStr + args);
|
|
|
|
|
|
|
|
if (result.exitCode != 0) {
|
|
|
|
std::cout << "\nError when extracting the ROM with error code: " << result.exitCode << " !" << std::endl;
|
|
|
|
std::cout << "Aborting...\n" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
void ExtractFunc(std::string fullPath, RomVersion version) {
|
2022-03-21 21:53:51 -04:00
|
|
|
std::vector<std::string> path = Util::split(fullPath, Util::pathSeparator());
|
|
|
|
std::string outPath = Util::join(Util::join("assets/extractor/xmls/output", path[4]), Util::basename(fullPath));
|
|
|
|
Util::mkdir(outPath);
|
2022-03-31 19:42:44 -04:00
|
|
|
ExtractFile(fullPath, outPath, outPath, version);
|
2022-03-21 21:53:51 -04:00
|
|
|
setCurrentStep("Extracting: " + Util::basename(fullPath));
|
|
|
|
extractedResources++;
|
|
|
|
}
|
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
void startWorker(RomVersion version) {
|
|
|
|
std::string path = "assets/extractor/xmls/";
|
2022-03-21 23:38:16 -04:00
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
path += GetXMLVersion(version);
|
|
|
|
|
2022-09-19 23:36:34 -04:00
|
|
|
// Util::write("tmp/baserom/version", (char*)&version.crc, sizeof(version.crc));
|
2022-03-21 21:53:51 -04:00
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
if (oldExtractMode)
|
|
|
|
{
|
|
|
|
std::vector<std::string> files;
|
|
|
|
Util::dirscan(path, files);
|
|
|
|
std::vector<std::string> xmlFiles;
|
|
|
|
|
|
|
|
const int num_threads = std::thread::hardware_concurrency();
|
|
|
|
ctpl::thread_pool pool(num_threads / 2);
|
|
|
|
for (auto& file : files) {
|
|
|
|
if (file.find(".xml") != std::string::npos) xmlFiles.push_back(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& file : xmlFiles) {
|
|
|
|
if (single_thread) {
|
|
|
|
ExtractFunc(file, version);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pool.push([file, version](int) {
|
|
|
|
ExtractFunc(file, version);
|
|
|
|
});
|
|
|
|
}
|
2022-03-21 21:53:51 -04:00
|
|
|
}
|
2022-03-31 19:42:44 -04:00
|
|
|
|
|
|
|
maxResources = xmlFiles.size();
|
2022-03-21 21:53:51 -04:00
|
|
|
}
|
2022-03-31 19:42:44 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string execStr = Util::format("assets/extractor/%s", isWindows() ? "ZAPD.exe" : "ZAPD.out");
|
|
|
|
std::string args = Util::format(" ed -eh -i %s -b tmp/rom.z64 -fl assets/extractor/filelists -o %s -osf %s -gsf 1 -rconf assets/extractor/Config_%s.xml -se OTR %s", path.c_str(), path + "../", path + "../", GetXMLVersion(version).c_str(), "");
|
|
|
|
ProcessResult result = NativeFS->LaunchProcess(execStr + args);
|
|
|
|
|
|
|
|
if (result.exitCode != 0) {
|
|
|
|
std::cout << "\nError when extracting the ROM with error code: " << result.exitCode << " !" << std::endl;
|
|
|
|
std::cout << "Aborting...\n" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("All done?\n");
|
|
|
|
}
|
2022-03-21 21:53:51 -04:00
|
|
|
|
2022-03-31 19:42:44 -04:00
|
|
|
maxResources = 1;
|
|
|
|
}
|
2022-03-21 21:53:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateWorker(const std::string& output) {
|
2022-03-31 19:42:44 -04:00
|
|
|
if (maxResources > 0 && !buildingOtr && (extractedResources >= maxResources || !oldExtractMode))
|
|
|
|
{
|
2022-03-21 21:53:51 -04:00
|
|
|
setCurrentStep("Building OTR...");
|
|
|
|
if (skipFrames < 3) {
|
|
|
|
skipFrames++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
buildingOtr = true;
|
2022-03-31 19:42:44 -04:00
|
|
|
|
|
|
|
if (single_thread || !oldExtractMode){
|
2022-03-21 21:53:51 -04:00
|
|
|
BuildOTR(output);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::thread otr(BuildOTR, output);
|
|
|
|
otr.detach();
|
|
|
|
}
|
2022-09-19 23:36:34 -04:00
|
|
|
}
|