mirror of
https://github.com/Luca1991/NDSFactory.git
synced 2025-07-09 13:30:12 +02:00
Added option to save all file IDs while extracting FAT data
This commit is contained in:
parent
ca8ad8259b
commit
dadd1d5c1f
@ -3,6 +3,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <format>
|
||||||
#include "ndsfactory.h"
|
#include "ndsfactory.h"
|
||||||
#include "fatstruct.h"
|
#include "fatstruct.h"
|
||||||
#include "crctable.h"
|
#include "crctable.h"
|
||||||
@ -61,6 +62,18 @@ bool NDSFactory::dumpDataFromFile(const std::string& romPath, const std::string&
|
|||||||
return false;
|
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)
|
bool NDSFactory::readBytesFromFile(std::vector<char>& byteBuffer, const std::string& romPath, uint32_t startAddr, uint32_t size)
|
||||||
{
|
{
|
||||||
@ -135,7 +148,7 @@ bool NDSFactory::checkArm9FooterPresence(const std::string& sectionPath, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
||||||
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath)
|
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs)
|
||||||
{
|
{
|
||||||
std::vector<char> fatDataBytes;
|
std::vector<char> fatDataBytes;
|
||||||
std::vector<char> fatBytes;
|
std::vector<char> fatBytes;
|
||||||
@ -169,7 +182,7 @@ bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std
|
|||||||
|
|
||||||
// This lambda function was written by NyuBlara, all credits to him.
|
// 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.
|
// I edited it a bit to make it work with the rest of the updated code.
|
||||||
auto parseFolder = [this, fntBytes, pfatrange, fatDataSectionPath, originalFatDataAddr](uint32_t folderId, std::string curPath, auto& parseFolder) {
|
auto parseFolder = [this, fntBytes, pfatrange, fatDataSectionPath, originalFatDataAddr, savePath, logFileIDs](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
|
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
|
// Only the lower 12 bit of the given offset are relevant
|
||||||
@ -236,6 +249,12 @@ bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std
|
|||||||
if (!std::filesystem::exists(newPath))
|
if (!std::filesystem::exists(newPath))
|
||||||
if (!std::filesystem::create_directory(newPath)) return false;
|
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 !
|
// Jump back to the FNT header and repeat the process for subdirectory !
|
||||||
if (!parseFolder(subFolderId, newPath, parseFolder)) return false;
|
if (!parseFolder(subFolderId, newPath, parseFolder)) return false;
|
||||||
}
|
}
|
||||||
@ -249,6 +268,12 @@ bool NDSFactory::extractFatData(const std::string& fatDataSectionPath, const std
|
|||||||
uint32_t fileSize = (pfatrange + fatOffset)->endAddr - (pfatrange + fatOffset)->startAddr;
|
uint32_t fileSize = (pfatrange + fatOffset)->endAddr - (pfatrange + fatOffset)->startAddr;
|
||||||
if (!dumpDataFromFile(fatDataSectionPath, newPath, fileStartAddr, fileSize)) return false;
|
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++;
|
fatOffset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public:
|
|||||||
NDSFactory();
|
NDSFactory();
|
||||||
bool loadRomHeader(const std::string& romPath, std::vector<char>& header);
|
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 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 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 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);
|
bool writeBytesToFile(std::vector<char>& byteBuffer, const std::string& savePath, uint32_t startAddr, uint32_t size);
|
||||||
@ -21,7 +22,7 @@ public:
|
|||||||
int getCardSizeInBytes(int cardType);
|
int getCardSizeInBytes(int cardType);
|
||||||
bool checkArm9FooterPresence(const std::string& sectionPath, uint32_t size);
|
bool checkArm9FooterPresence(const std::string& sectionPath, uint32_t size);
|
||||||
bool extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
bool extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
||||||
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath);
|
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs);
|
||||||
bool patchFat(const std::string& sectionPath, uint32_t shiftSize, 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);
|
uint16_t calcHeaderCrc16(const std::vector<char>& romHeader);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#ifndef REVISION_H
|
#ifndef REVISION_H
|
||||||
#define REVISION_H
|
#define REVISION_H
|
||||||
|
|
||||||
#define GIT_COMMIT_HASH "e788d95"
|
#define GIT_COMMIT_HASH "fb12309"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -108,6 +108,6 @@ private:
|
|||||||
QString extractPackerHeaderTableData(int index);
|
QString extractPackerHeaderTableData(int index);
|
||||||
|
|
||||||
bool extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
bool extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
||||||
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath);
|
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs);
|
||||||
bool patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath);
|
bool patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath);
|
||||||
};
|
};
|
||||||
|
@ -697,6 +697,17 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_41">
|
<layout class="QHBoxLayout" name="horizontalLayout_41">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
|
|
||||||
bool MainWindow::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
bool MainWindow::extractFatData(const std::string& fatDataSectionPath, const std::string& fatSectionPath,
|
||||||
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath)
|
const std::string& fntSectionPath, uint32_t originalFatDataAddr, const std::string& savePath, bool logFileIDs)
|
||||||
{
|
{
|
||||||
return ndsFactory.extractFatData(fatDataSectionPath, fatSectionPath, fntSectionPath, originalFatDataAddr, savePath);
|
return ndsFactory.extractFatData(fatDataSectionPath, fatSectionPath, fntSectionPath, originalFatDataAddr, savePath, logFileIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath)
|
bool MainWindow::patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath)
|
||||||
|
@ -54,10 +54,11 @@ void MainWindow::on_fatExtractorExtractBtn_clicked()
|
|||||||
|
|
||||||
if (!dirPath.isNull())
|
if (!dirPath.isNull())
|
||||||
extractFatData(ui->fatExtractorFatDataPathEdt->text().toStdString(),
|
extractFatData(ui->fatExtractorFatDataPathEdt->text().toStdString(),
|
||||||
ui->fatExtractorFatPathEdt->text().toStdString(),
|
ui->fatExtractorFatPathEdt->text().toStdString(),
|
||||||
ui->fatExtractorFntPathEdt->text().toStdString(),
|
ui->fatExtractorFntPathEdt->text().toStdString(),
|
||||||
ui->fatExtractorOriginalFatFilesAddrEdt->text().toUInt(nullptr, 16),
|
ui->fatExtractorOriginalFatFilesAddrEdt->text().toUInt(nullptr, 16),
|
||||||
dirPath.toStdString()) ? QMessageBox::information(this, tr("NDS Factory"), tr("FAT files extraction completed!"))
|
dirPath.toStdString(),
|
||||||
|
ui->fatExtractorSaveFileIDsCbx->isChecked()) ? QMessageBox::information(this, tr("NDS Factory"), tr("FAT files extraction completed!"))
|
||||||
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error extracting FAT files!"));
|
: QMessageBox::critical(this, tr("NDS Factory"), tr("Error extracting FAT files!"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user