This commit is contained in:
Luca D'Amico
2024-08-04 20:09:19 +02:00
committed by GitHub
parent ec81e2bfbe
commit aa2ed50ade
21 changed files with 720 additions and 252 deletions

View File

@@ -4,7 +4,7 @@
#include "./../../ui_mainwindow.h"
void MainWindow::on_fatPatchingLoadFatBtn_clicked()
void MainWindow::on_fatPatcherLoadFatBtn_clicked()
{
QString fatPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
@@ -14,15 +14,15 @@ void MainWindow::on_fatPatchingLoadFatBtn_clicked()
if( !fatPath.isNull() )
{
ui->fatPatchingFatPathEdt->setText(fatPath.toUtf8());
ui->fatPatcherFatPathEdt->setText(fatPath.toUtf8());
}
}
void MainWindow::on_fatPatchingPatchFatBtn_clicked()
void MainWindow::on_fatPatcherPatchFatBtn_clicked()
{
uint32_t positionDiff = 0;
uint32_t originalPos = ui->fatPatchingOriginalFatFilesAddrEdt->text().toUInt(nullptr, 16);
uint32_t newPos = ui->fatPatchingNewFatFilesAddrEdt->text().toUInt(nullptr, 16);
uint32_t originalPos = ui->fatPatcherOriginalFatFilesAddrEdt->text().toUInt(nullptr, 16);
uint32_t newPos = ui->fatPatcherNewFatFilesAddrEdt->text().toUInt(nullptr, 16);
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
@@ -42,7 +42,7 @@ void MainWindow::on_fatPatchingPatchFatBtn_clicked()
positionDiff = originalPos-newPos;
}
patchFat(ui->fatPatchingFatPathEdt->text().toStdString(), positionDiff, dirPath.toStdString())
patchFat(ui->fatPatcherFatPathEdt->text().toStdString(), positionDiff, dirPath.toStdString())
? QMessageBox::information(this, tr("NDS Factory"), tr("FAT patching completed!"))
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error patching FAT!"));

View File

@@ -94,23 +94,23 @@ void MainWindow::generateHeader(NDSHeader* pRomHeader)
bool MainWindow::writeHeader(const std::string& savePath)
{
std::vector<char> romHeader(sizeof(NDSHeader));
NDSHeader* pRomHeader = reinterpret_cast<NDSHeader*>(romHeader.data());
std::vector<char> romHeaderBuffer(sizeof(NDSHeader));
NDSHeader* pRomHeader = reinterpret_cast<NDSHeader*>(romHeaderBuffer.data());
generateHeader(pRomHeader);
return ndsFactory.writeBytesToFile(romHeader, savePath, 0, sizeof(NDSHeader));;
return ndsFactory.writeBytesToFile(romHeaderBuffer, savePath, 0, sizeof(NDSHeader));;
}
void MainWindow::calcHeaderCrc16()
{
std::vector<char> romHeader(sizeof(NDSHeader));
NDSHeader* pRomHeader = reinterpret_cast<NDSHeader*>(romHeader.data());
std::vector<char> romHeaderBuffer(sizeof(NDSHeader));
NDSHeader* pRomHeader = reinterpret_cast<NDSHeader*>(romHeaderBuffer.data());
generateHeader(pRomHeader);
QModelIndex headerCrcIndex = ui->packerHeaderDataTable->model()->index(NDSHeaderNames::HeaderCRC, 1);
ui->packerHeaderDataTable->model()->setData(headerCrcIndex, QString::number(ndsFactory.calcHeaderCrc16(romHeader), 16), Qt::EditRole);
ui->packerHeaderDataTable->model()->setData(headerCrcIndex, QString::number(ndsFactory.calcHeaderCrc16(romHeaderBuffer), 16), Qt::EditRole);
}
bool MainWindow::writeArm9Bin(const std::string& savePath, bool isArm9FooterPresent)
@@ -161,7 +161,7 @@ bool MainWindow::writeArm9Overlay(const std::string& savePath)
extractPackerHeaderTableData(NDSHeaderNames::ARM9OverlaySize).toUInt(nullptr, 16));
}
bool MainWindow::writeArm9OverlayFiles(const std::string& savePath)
bool MainWindow::writeArm9OverlayFiles([[maybe_unused]] const std::string& savePath)
{
return false; // TODO: implement me!
}
@@ -175,7 +175,7 @@ bool MainWindow::writeArm7Overlay(const std::string& savePath)
extractPackerHeaderTableData(NDSHeaderNames::ARM9OverlaySize).toUInt(nullptr, 16));
}
bool MainWindow::writeArm7OverlayFiles(const std::string& savePath)
bool MainWindow::writeArm7OverlayFiles([[maybe_unused]] const std::string& savePath)
{
return false; // TODO: implement me!
}
@@ -268,23 +268,23 @@ bool MainWindow::writeFatPadding(char paddingType, const std::string& savePath)
size);
}
bool MainWindow::writeArm9OverlayPadding(char paddingType, const std::string& savePath)
bool MainWindow::writeArm9OverlayPadding([[maybe_unused]] char paddingType, [[maybe_unused]] const std::string& savePath)
{ // FIXME TODO
return true;
}
bool MainWindow::writeArm9OverlayFilesPadding(char paddingType, const std::string& savePath)
bool MainWindow::writeArm9OverlayFilesPadding([[maybe_unused]] char paddingType, [[maybe_unused]] const std::string& savePath)
{ // FIXME TODO
return true;
}
bool MainWindow::writeArm7OverlayPadding(char paddingType, const std::string& savePath)
bool MainWindow::writeArm7OverlayPadding([[maybe_unused]] char paddingType, [[maybe_unused]] const std::string& savePath)
{ // FIXME TODO
return true;
}
bool MainWindow::writeArm7OverlayFilesPadding(char paddingType, const std::string& savePath)
bool MainWindow::writeArm7OverlayFilesPadding([[maybe_unused]] char paddingType, [[maybe_unused]] const std::string& savePath)
{ // FIXME TODO
return true;
}

View File

@@ -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)

View File

@@ -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!"));
}
}