Compare commits

..

No commits in common. "a2739a9ca83c33d57f2f5b586f633b205f473b92" and "fb12309ea06a3405a116b491592ff6fad49ec912" have entirely different histories.

12 changed files with 77 additions and 117 deletions

View File

@ -84,7 +84,7 @@ else()
endif()
# Set C++ standard for the target
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
# Enable Qt's automatic features for the target
set_target_properties(${PROJECT_NAME} PROPERTIES

View File

@ -3,7 +3,6 @@
#include <fstream>
#include <cmath>
#include <filesystem>
#include <format>
#include "ndsfactory.h"
#include "fatstruct.h"
#include "crctable.h"
@ -62,18 +61,6 @@ bool NDSFactory::dumpDataFromFile(const std::string& romPath, const std::string&
return false;
}
bool NDSFactory::logToFile(const std::string& logPath, const std::string& log)
{
std::ofstream savedFile(logPath, std::ios::out | std::ios::binary | std::ios::app);
if (savedFile.is_open())
{
savedFile.write(log.c_str(), log.size());
savedFile.close();
return true;
}
return false;
}
bool NDSFactory::readBytesFromFile(std::vector<char>& byteBuffer, const std::string& romPath, uint32_t startAddr, uint32_t size)
{
@ -148,7 +135,7 @@ bool NDSFactory::checkArm9FooterPresence(const std::string& sectionPath, uint32_
}
bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs)
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath)
{
std::vector<char> fatDataBytes;
std::vector<char> fatBytes;
@ -182,7 +169,7 @@ bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std
// This lambda function was written by NyuBlara, all credits to him.
// I edited it a bit to make it work with the rest of the updated code.
auto parseFolder = [this, fntBytes, pfatrange, fatDataSectionPath, originalFatDataAddr, savePath, logFileIDs](uint32_t folderId, std::string curPath, auto& parseFolder) {
auto parseFolder = [this, fntBytes, pfatrange, fatDataSectionPath, originalFatDataAddr](uint32_t folderId, std::string curPath, auto& parseFolder) {
uint32_t currentOffset = 8 * (folderId & FNT_HEADER_OFFSET_MASK); // offset for the current directory's info in the FNT header
// Only the lower 12 bit of the given offset are relevant
@ -249,12 +236,6 @@ bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std
if (!std::filesystem::exists(newPath))
if (!std::filesystem::create_directory(newPath)) return false;
if (logFileIDs)
{
std::string log = std::format("{:x}",subFolderId) + "::D::" + newPath.substr(savePath.size()+1) + '\n';
if (!logToFile(savePath + "/_file_IDs.txt", log)) return false;
}
// Jump back to the FNT header and repeat the process for subdirectory !
if (!parseFolder(subFolderId, newPath, parseFolder)) return false;
}
@ -268,12 +249,6 @@ bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std
uint32_t fileSize = (pfatrange + fatOffset)->endAddr - (pfatrange + fatOffset)->startAddr;
if (!dumpDataFromFile(fatDataSectionPath, newPath, fileStartAddr, fileSize)) return false;
if (logFileIDs)
{
std::string log = std::format("{:x}", fatOffset) + "::F::" + newPath.substr(savePath.size()+1) + '\n';
if (!logToFile(savePath + "/_file_IDs.txt", log)) return false;
}
fatOffset++;
}
}

View File

@ -14,7 +14,6 @@ public:
NDSFactory();
bool loadRomHeader(const std::string& romPath, std::vector<char>& header);
bool dumpDataFromFile(const std::string& romPath, const std::string& savePath, uint32_t startAddr, uint32_t size);
bool logToFile(const std::string& logPath, const std::string& log);
bool readBytesFromFile(std::vector<char>& byteBuffer, const std::string& romPath, uint32_t startAddr, uint32_t size);
bool writeSectionToFile(const std::string& sectionPath, const std::string& savePath, uint32_t startAddr, uint32_t size);
bool writeBytesToFile(std::vector<char>& byteBuffer, const std::string& savePath, uint32_t startAddr, uint32_t size);
@ -22,7 +21,7 @@ public:
int getCardSizeInBytes(int cardType);
bool checkArm9FooterPresence(const std::string& sectionPath, uint32_t size);
bool extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs);
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath);
bool patchFat(const std::string& sectionPath, uint32_t shiftSize, const std::string& savePath);
uint16_t calcHeaderCrc16(const std::vector<char>& romHeader);

View File

@ -1,6 +1,6 @@
#ifndef REVISION_H
#define REVISION_H
#define GIT_COMMIT_HASH "fb12309"
#define GIT_COMMIT_HASH "e788d95"
#endif

View File

@ -108,6 +108,6 @@ private:
QString extractPackerHeaderTableData(int index);
bool extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs);
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath);
bool patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath);
};

View File

@ -697,17 +697,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QCheckBox" name="fatExtractorSaveFileIDsCbx">
<property name="text">
<string>Save file IDs to _file_IDs.txt (required for games that access files by their ID)</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_41">
<property name="leftMargin">

View File

@ -2,9 +2,9 @@
bool MainWindow::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs)
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath)
{
return ndsFactory.extractFatData(fatDataSectionPath, fatSectionPath, fntSectionPath, originalFatDataAddr, savePath, logFileIDs);
return ndsFactory.extractFatData(fatDataSectionPath, fatSectionPath, fntSectionPath, originalFatDataAddr, savePath);
}
bool MainWindow::patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath)

View File

@ -8,7 +8,7 @@ void MainWindow::on_fatExtractorLoadFatDataBtn_clicked()
QString FatDataPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Fat Data",
"",
QDir::currentPath(),
"NDS FAT_DATA (*.bin)");
if (!FatDataPath.isNull())
@ -22,7 +22,7 @@ void MainWindow::on_fatExtractorLoadFatBtn_clicked()
QString FatPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Fat",
"",
QDir::currentPath(),
"NDS FAT (*.bin)");
if (!FatPath.isNull())
@ -36,7 +36,7 @@ void MainWindow::on_fatExtractorLoadFntBtn_clicked()
QString FntPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Fnt",
"",
QDir::currentPath(),
"NDS FNT (*.bin)");
if (!FntPath.isNull())
@ -54,11 +54,10 @@ void MainWindow::on_fatExtractorExtractBtn_clicked()
if (!dirPath.isNull())
extractFatData(ui->fatExtractorFatDataPathEdt->text().toStdString(),
ui->fatExtractorFatPathEdt->text().toStdString(),
ui->fatExtractorFntPathEdt->text().toStdString(),
ui->fatExtractorOriginalFatFilesAddrEdt->text().toUInt(nullptr, 16),
dirPath.toStdString(),
ui->fatExtractorSaveFileIDsCbx->isChecked()) ? QMessageBox::information(this, tr("NDS Factory"), tr("FAT files extraction completed!"))
ui->fatExtractorFatPathEdt->text().toStdString(),
ui->fatExtractorFntPathEdt->text().toStdString(),
ui->fatExtractorOriginalFatFilesAddrEdt->text().toUInt(nullptr, 16),
dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("FAT files extraction completed!"))
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error extracting FAT files!"));
}
@ -68,7 +67,7 @@ void MainWindow::on_fatPatcherLoadFatBtn_clicked()
QString fatPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Fat",
"",
QDir::currentPath(),
"NDS Fat (*.bin)");
if( !fatPath.isNull() )

View File

@ -35,7 +35,7 @@ void MainWindow::on_packerLoadArm9BinBtn_clicked()
QString arm9BinPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Arm9Bin",
"",
QDir::currentPath(),
"NDS Arm9Bin (*.bin)");
if(!arm9BinPath.isNull())
@ -49,7 +49,7 @@ void MainWindow::on_packerLoadArm7BinBtn_clicked()
QString arm7BinPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Arm7Bin",
"",
QDir::currentPath(),
"NDS Arm7Bin (*.bin)");
if(!arm7BinPath.isNull())
@ -63,7 +63,7 @@ void MainWindow::on_packerLoadFntBtn_clicked()
QString fntPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Fnt",
"",
QDir::currentPath(),
"NDS Fnt (*.bin)");
if(!fntPath.isNull())
@ -77,7 +77,7 @@ void MainWindow::on_packerLoadFatBtn_clicked()
QString fatPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Fat",
"",
QDir::currentPath(),
"NDS Fat (*.bin)");
if(!fatPath.isNull())
@ -91,7 +91,7 @@ void MainWindow::on_packerLoadArm9OverlayBtn_clicked()
QString arm9OverlayPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Arm9Overlay",
"",
QDir::currentPath(),
"NDS A9OVR (*.bin)");
if( !arm9OverlayPath.isNull() )
@ -105,7 +105,7 @@ void MainWindow::on_packerLoadArm9OverlayFilesBtn_clicked()
QString arm9OverlayFilesPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Arm9Overlay Data",
"",
QDir::currentPath(),
"NDS A9OVR_DATA (*.bin)");
if(!arm9OverlayFilesPath.isNull())
@ -119,7 +119,7 @@ void MainWindow::on_packerLoadArm7OverlayBtn_clicked()
QString arm7OverlayPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Arm7Overlay",
"",
QDir::currentPath(),
"NDS A7OVR (*.bin)");
if(!arm7OverlayPath.isNull())
@ -133,7 +133,7 @@ void MainWindow::on_packerLoadArm7OverlayFilesBtn_clicked()
QString arm7OverlayFilesPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Arm7Overlay Data",
"",
QDir::currentPath(),
"NDS A7OVR_DATA (*.bin)");
if(!arm7OverlayFilesPath.isNull())
@ -147,7 +147,7 @@ void MainWindow::on_packerLoadIconTitleBtn_clicked()
QString iconTitlePath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS IconTitleLogo",
"",
QDir::currentPath(),
"NDS ITL (*.bin)");
if(!iconTitlePath.isNull())
@ -161,7 +161,7 @@ void MainWindow::on_packerLoadFatFilesBtn_clicked()
QString fatFilesPath = QFileDialog::getOpenFileName(
Q_NULLPTR,
"NDS Fat Data",
"",
QDir::currentPath(),
"NDS FAT_DATA (*.bin)");
if(!fatFilesPath.isNull())

View File

@ -23,26 +23,14 @@ void MainWindow::enableExtractionButtons()
{
ui->unpackerExtractorGbx->setEnabled(true);
ui->unpackerExtraGbx->setEnabled(true);
if (ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlayAddress, 1).data().toString().toUInt(nullptr,16) == 0)
{
if (ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM9OverlayAddress, 1).data().toString().toUInt(nullptr,16) == 0){
ui->unpackerDumpArm9OverlayBtn->setEnabled(false);
ui->unpackerDumpArm9OverlayFilesBtn->setEnabled(false);
}
else
{
ui->unpackerDumpArm9OverlayBtn->setEnabled(true);
ui->unpackerDumpArm9OverlayFilesBtn->setEnabled(true);
}
if (ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlayAddress, 1).data().toString().toUInt(nullptr,16) == 0)
{
if (ui->unpackerHeaderDataTable->model()->index(NDSHeaderNames::ARM7OverlayAddress, 1).data().toString().toUInt(nullptr,16) == 0){
ui->unpackerDumpArm7OverlayBtn->setEnabled(false);
ui->unpackerDumpArm7OverlayFilesBtn->setEnabled(false);
}
else
{
ui->unpackerDumpArm7OverlayBtn->setEnabled(true);
ui->unpackerDumpArm7OverlayFilesBtn->setEnabled(true);
}
}
void MainWindow::disableExtractionButtons()

View File

@ -3,7 +3,6 @@
#include <QMessageBox>
#include "./../../mainwindow.h"
#include "./../../ui_mainwindow.h"
#include "./../../utils/filepicker.h"
void MainWindow::on_loadRomBtn_clicked()
@ -35,7 +34,11 @@ void MainWindow::on_loadRomBtn_clicked()
void MainWindow::on_unpackerDumpHeaderBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS Header", "header.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS Header",
"header.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpHeader(dirPath.toStdString()));
@ -43,7 +46,11 @@ void MainWindow::on_unpackerDumpHeaderBtn_clicked()
void MainWindow::on_unpackerDumpArm9Btn_clicked()
{
QString dirPath = customSaveFileDialog("NDS ARM9", "arm9.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS ARM9",
"arm9.bin",
"Binary (*.bin)");
QMessageBox::StandardButton dumpExtraBytes = QMessageBox::question(
this,
@ -57,7 +64,11 @@ void MainWindow::on_unpackerDumpArm9Btn_clicked()
void MainWindow::on_unpackerDumpArm7Btn_clicked()
{
QString dirPath = customSaveFileDialog("NDS ARM7", "arm7.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS ARM7",
"arm7.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpArm7Bin(dirPath.toStdString()));
@ -65,7 +76,11 @@ void MainWindow::on_unpackerDumpArm7Btn_clicked()
void MainWindow::on_unpackerDumpFntBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS FNT", "fnt.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS FNT",
"fnt.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpFnt(dirPath.toStdString()));
@ -73,7 +88,11 @@ void MainWindow::on_unpackerDumpFntBtn_clicked()
void MainWindow::on_unpackerDumpFatBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS FAT", "fat.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS FAT",
"fat.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpFat(dirPath.toStdString()));
@ -81,7 +100,11 @@ void MainWindow::on_unpackerDumpFatBtn_clicked()
void MainWindow::on_unpackerDumpArm9OverlayBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS ARM9 Overlay", "a9ovr.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS ARM9 Overlay",
"a9ovr.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpArm9Overlay(dirPath.toStdString()));
@ -89,7 +112,11 @@ void MainWindow::on_unpackerDumpArm9OverlayBtn_clicked()
void MainWindow::on_unpackerDumpArm7OverlayBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS ARM7 Overlay", "a7ovr.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS ARM7 Overlay",
"a7ovr.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpArm7Overlay(dirPath.toStdString()));
@ -97,7 +124,11 @@ void MainWindow::on_unpackerDumpArm7OverlayBtn_clicked()
void MainWindow::on_unpackerDumpIconTitleLogoBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS IconTitleLogo", "itl.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS IconTitleLogo",
"itl.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpIconTitle(dirPath.toStdString()));
@ -105,7 +136,11 @@ void MainWindow::on_unpackerDumpIconTitleLogoBtn_clicked()
void MainWindow::on_unpackerDumpFatFilesBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS FAT Files", "fat_data.bin", "Binary (*.bin)");
QString dirPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
"NDS FAT Files",
"fat_data.bin",
"Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpFatFiles(dirPath.toStdString()));
@ -113,18 +148,14 @@ void MainWindow::on_unpackerDumpFatFilesBtn_clicked()
void MainWindow::on_unpackerDumpArm9OverlayFilesBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS ARM9 Overlay Data", "a9ovr_data.bin", "Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpArm9OverlayFiles(dirPath.toStdString()));
QMessageBox::warning(this, tr("NDS Factory"), tr("This function is currently not implemented!"));
//dumpArm9OverlayFiles()
}
void MainWindow::on_unpackerDumpArm7OverlayFilesBtn_clicked()
{
QString dirPath = customSaveFileDialog("NDS ARM7 Overlay Data", "a7ovr_data.bin", "Binary (*.bin)");
if (!dirPath.isNull())
notifyExtractionResult(dumpArm7OverlayFiles(dirPath.toStdString()));
QMessageBox::warning(this, tr("NDS Factory"), tr("This function is currently not implemented!"));
//dumpArm7OverlayFiles()
}
void MainWindow::on_unpackerDumpEverythingBtn_clicked()

View File

@ -1,21 +0,0 @@
#pragma once
#include <QFileDialog>
QString customSaveFileDialog(const QString& title, const QString& defaultName, const QString& filter)
{
static QString lastUsedPath;
QString selectedPath = QFileDialog::getSaveFileName(
Q_NULLPTR,
title,
lastUsedPath + defaultName,
filter);
if (!selectedPath.isNull())
lastUsedPath = selectedPath.mid(0, selectedPath.lastIndexOf('/', Qt::CaseInsensitive)+1);
return selectedPath;
}