mirror of
https://github.com/Luca1991/NDSFactory.git
synced 2026-02-04 05:36:15 +01:00
v1.1 (#16)
This commit is contained in:
@@ -9,19 +9,20 @@
|
||||
#include "../../../ndsfactory/fatstruct.h"
|
||||
|
||||
// Byte offsets for interpreting memory
|
||||
|
||||
#define SECOND_BYTE_SHIFT 8
|
||||
#define THIRD_BYTE_SHIFT 16
|
||||
#define FOURTH_BYTE_SHIFT 24
|
||||
|
||||
// Magic values for FAT extraction
|
||||
|
||||
#define CONTROL_BYTE_LENGTH_MASK 0x7F
|
||||
#define CONTROL_BYTE_DIR_MASK 0x80
|
||||
#define DUMMY_CONTROL_VALUE 0xFF
|
||||
#define FNT_HEADER_OFFSET_MASK 0XFFF
|
||||
#define ROOT_DIRECTORY_ADDRESS 0xF000
|
||||
|
||||
// Size constants
|
||||
#define ICON_TITLE_SIZE 0xA00
|
||||
|
||||
void MainWindow::populateHeader(NDSHeader* ndsHeader)
|
||||
{
|
||||
auto* headerDataModel = new NDSHeaderModel(ndsHeader);
|
||||
@@ -107,7 +108,7 @@ bool MainWindow::dumpArm9Overlay(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlaySize, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm9OverlayFiles(const std::string& dirPath)
|
||||
bool MainWindow::dumpArm9OverlayFiles([[maybe_unused]] const std::string& dirPath)
|
||||
{
|
||||
return false; // TODO: implement me!
|
||||
}
|
||||
@@ -121,7 +122,7 @@ bool MainWindow::dumpArm7Overlay(const std::string& dirPath)
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlaySize, 1).data().toString().toUInt(nullptr,16));
|
||||
}
|
||||
|
||||
bool MainWindow::dumpArm7OverlayFiles(const std::string& dirPath)
|
||||
bool MainWindow::dumpArm7OverlayFiles([[maybe_unused]] const std::string& dirPath)
|
||||
{
|
||||
return false; // TODO: implement me!
|
||||
}
|
||||
@@ -132,7 +133,7 @@ bool MainWindow::dumpIconTitle(const std::string& dirPath)
|
||||
ui->loadedRomPath->text().toStdString(),
|
||||
dirPath,
|
||||
ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::IconTitleAddress, 1).data().toString().toUInt(nullptr,16),
|
||||
0xA00);
|
||||
ICON_TITLE_SIZE);
|
||||
}
|
||||
|
||||
bool MainWindow::dumpFatFiles(const std::string& dirPath)
|
||||
@@ -150,34 +151,23 @@ bool MainWindow::dumpFatFiles(const std::string& dirPath)
|
||||
|
||||
bool MainWindow::dumpEverything(QString dirPath)
|
||||
{
|
||||
if(!dumpHeader(QDir::toNativeSeparators(dirPath+"/header.bin").toStdString()))
|
||||
return false;
|
||||
if(!dumpArm9Bin(QDir::toNativeSeparators(dirPath+"/arm9.bin").toStdString(), true))
|
||||
return false;
|
||||
if(!dumpArm7Bin(QDir::toNativeSeparators(dirPath+"/arm7.bin").toStdString()))
|
||||
return false;
|
||||
if(!dumpFnt(QDir::toNativeSeparators(dirPath+"/fnt.bin").toStdString()))
|
||||
return false;
|
||||
if(!dumpFat(QDir::toNativeSeparators(dirPath+"/fat.bin").toStdString()))
|
||||
return false;
|
||||
bool result = true;
|
||||
result &= dumpHeader(QDir::toNativeSeparators(dirPath+"/header.bin").toStdString());
|
||||
result &= dumpArm9Bin(QDir::toNativeSeparators(dirPath+"/arm9.bin").toStdString(), true);
|
||||
result &= dumpArm7Bin(QDir::toNativeSeparators(dirPath+"/arm7.bin").toStdString());
|
||||
result &= dumpFnt(QDir::toNativeSeparators(dirPath+"/fnt.bin").toStdString());
|
||||
result &= dumpFat(QDir::toNativeSeparators(dirPath+"/fat.bin").toStdString());
|
||||
if(ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlayAddress, 1).data().toString().toUInt(nullptr,16) != 0) {
|
||||
if(!dumpArm9Overlay(QDir::toNativeSeparators(dirPath+"/a9ovr.bin").toStdString()))
|
||||
return false;
|
||||
if(!dumpArm9OverlayFiles(QDir::toNativeSeparators(dirPath+"/a9ovr_data.bin").toStdString()))
|
||||
return false;
|
||||
}
|
||||
result &= dumpArm9Overlay(QDir::toNativeSeparators(dirPath+"/a9ovr.bin").toStdString());
|
||||
result &= dumpArm9OverlayFiles(QDir::toNativeSeparators(dirPath+"/a9ovr_data.bin").toStdString());
|
||||
}
|
||||
if(ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlayAddress, 1).data().toString().toUInt(nullptr,16) != 0) {
|
||||
if(!dumpArm7Overlay(QDir::toNativeSeparators(dirPath+"/a7ovr.bin").toStdString()))
|
||||
return false;
|
||||
if(!dumpArm7OverlayFiles(QDir::toNativeSeparators(dirPath+"/a7ovr_data.bin").toStdString()))
|
||||
return false;
|
||||
}
|
||||
if(!dumpIconTitle(QDir::toNativeSeparators(dirPath+"/itl.bin").toStdString()))
|
||||
return false;
|
||||
if(!dumpFatFiles(QDir::toNativeSeparators(dirPath+"/fat_data.bin").toStdString()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
result &= dumpArm7Overlay(QDir::toNativeSeparators(dirPath+"/a7ovr.bin").toStdString());
|
||||
result &= dumpArm7OverlayFiles(QDir::toNativeSeparators(dirPath+"/a7ovr_data.bin").toStdString());
|
||||
}
|
||||
result &= dumpIconTitle(QDir::toNativeSeparators(dirPath+"/itl.bin").toStdString());
|
||||
result &= dumpFatFiles(QDir::toNativeSeparators(dirPath+"/fat_data.bin").toStdString());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool MainWindow::decodeFatFiles(QString dirPath)
|
||||
|
||||
@@ -41,10 +41,7 @@ void MainWindow::on_unpackerDumpHeaderBtn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpHeader(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpHeader(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpArm9Btn_clicked()
|
||||
@@ -62,11 +59,7 @@ void MainWindow::on_unpackerDumpArm9Btn_clicked()
|
||||
QMessageBox::Yes|QMessageBox::No);
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpArm9Bin(dirPath.toStdString(), dumpExtraBytes == QMessageBox::Yes ? true : false)
|
||||
? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpArm9Bin(dirPath.toStdString(), dumpExtraBytes == QMessageBox::Yes ? true : false));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpArm7Btn_clicked()
|
||||
@@ -78,10 +71,7 @@ void MainWindow::on_unpackerDumpArm7Btn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpArm7Bin(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpArm7Bin(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpFntBtn_clicked()
|
||||
@@ -93,10 +83,7 @@ void MainWindow::on_unpackerDumpFntBtn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpFnt(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpFnt(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpFatBtn_clicked()
|
||||
@@ -108,10 +95,7 @@ void MainWindow::on_unpackerDumpFatBtn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpFat(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpFat(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpArm9OverlayBtn_clicked()
|
||||
@@ -123,10 +107,7 @@ void MainWindow::on_unpackerDumpArm9OverlayBtn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpArm9Overlay(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpArm9Overlay(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpArm7OverlayBtn_clicked()
|
||||
@@ -138,10 +119,7 @@ void MainWindow::on_unpackerDumpArm7OverlayBtn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpArm7Overlay(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpArm7Overlay(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpIconTitleLogoBtn_clicked()
|
||||
@@ -153,10 +131,7 @@ void MainWindow::on_unpackerDumpIconTitleLogoBtn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpIconTitle(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpIconTitle(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpFatFilesBtn_clicked()
|
||||
@@ -168,10 +143,7 @@ void MainWindow::on_unpackerDumpFatFilesBtn_clicked()
|
||||
"Binary (*.bin)");
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpFatFiles(dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpFatFiles(dirPath.toStdString()));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDumpArm9OverlayFilesBtn_clicked()
|
||||
@@ -194,10 +166,7 @@ void MainWindow::on_unpackerDumpEverythingBtn_clicked()
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
dumpEverything(dirPath) ? QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
notifyExtractionResult(dumpEverything(dirPath));
|
||||
}
|
||||
|
||||
void MainWindow::on_unpackerDecodeFatFilesBtn_clicked()
|
||||
@@ -208,8 +177,17 @@ void MainWindow::on_unpackerDecodeFatFilesBtn_clicked()
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
|
||||
if (!dirPath.isNull())
|
||||
{
|
||||
decodeFatFiles(dirPath) ? QMessageBox::information(this, tr("NDS Factory"), tr("FAT files successfully decoded!"))
|
||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error during FAT file decoding!"));
|
||||
}
|
||||
notifyExtractionResult(decodeFatFiles(dirPath));
|
||||
}
|
||||
|
||||
void MainWindow::notifyExtractionResult(bool result)
|
||||
{
|
||||
if(result)
|
||||
{
|
||||
QMessageBox::information(this, tr("NDS Factory"), tr("Extraction completed!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(this, tr("NDS Factory"), tr("Error during the extraction!"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user