NDSFactory/ui/mainwindow.h
NyuBlara ec81e2bfbe
Feat/fat decoding (#14)
* First step in implementing FAT file decoding : brute-force extraction without FNT lookup.

The FAT alone contains enough information to extract every file in a
folder chosen by the user. However, reference to the file name table
(FNT) is needed to restore the files' names and the directory structure
(and avoid dumping useless data that may be left over in the data
section).

This commit only implements the dumping of all data by incrementing
through the FAT and writing every section marked by a FAT range into a
separate file, giving them incremental names.

The next commit will use the FNT to name them properly.

* Proper FAT decoding : FNT lookup and directory structure

Code comments explain the algorithm (which was understood thanks to the 
wonderfully simple "FNT-Tool" script at : 
https://github.com/RoadrunnerWMC/FNT-Tool) ; the implementation is more 
or less a C++ port of the Python code.

Everything may still be a little dirty, but it works !

* Updated README!

* Updated README!

* MINOR compliance modifications 

- Removed extra entry in .gitignore
- Removed superfluous debug inclusions 
- Replaced magic values by preprocessor macros

Co-authored-by: rblard <rblard@enseirb-matmeca.fr>
2022-11-16 18:46:13 +01:00

117 lines
4.4 KiB
C++

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <cstdint>
#include "../ndsfactory/ndsfactory.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_loadRomBtn_clicked();
void on_unpackerDumpHeaderBtn_clicked();
void on_unpackerDumpArm9Btn_clicked();
void on_unpackerDumpArm7Btn_clicked();
void on_unpackerDumpFntBtn_clicked();
void on_unpackerDumpFatBtn_clicked();
void on_unpackerDumpArm9OverlayBtn_clicked();
void on_unpackerDumpArm7OverlayBtn_clicked();
void on_unpackerDumpIconTitleLogoBtn_clicked();
void on_unpackerDumpFatFilesBtn_clicked();
void on_unpackerDumpArm9OverlayFilesBtn_clicked();
void on_unpackerDumpArm7OverlayFilesBtn_clicked();
void on_unpackerDumpEverythingBtn_clicked();
void on_unpackerDecodeFatFilesBtn_clicked();
void on_actionExit_triggered();
void on_actionAbout_triggered();
void on_packerLoadHeaderBtn_clicked();
void on_packerLoadArm9BinBtn_clicked();
void on_packerLoadArm7BinBtn_clicked();
void on_packerLoadFntBtn_clicked();
void on_packerLoadFatBtn_clicked();
void on_packerLoadArm9OverlayBtn_clicked();
void on_packerLoadArm9OverlayFilesBtn_clicked();
void on_packerLoadArm7OverlayBtn_clicked();
void on_packerLoadArm7OverlayFilesBtn_clicked();
void on_packerLoadIconTitleBtn_clicked();
void on_packerLoadFatFilesBtn_clicked();
void on_packerBuildNDSRomBtn_clicked();
void on_fatPatchingLoadFatBtn_clicked();
void on_fatPatchingPatchFatBtn_clicked();
void on_packerCalcHeaderCrcBtn_clicked();
private:
Ui::MainWindow *ui;
NDSFactory ndsFactory;
std::vector<char> romHeader;
void populateHeader(NDSHeader* ndsHeader);
void enableExtractionButtons();
void disableExtractionButtons();
bool dumpHeader(const std::string& dirPath);
bool dumpArm9Bin(const std::string& dirPath, bool dumpExtraBytes);
bool dumpArm7Bin(const std::string& dirPath);
bool dumpFnt(const std::string& dirPath);
bool dumpFat(const std::string& dirPath);
bool dumpArm9Overlay(const std::string& dirPath);
bool dumpArm9OverlayFiles(const std::string& dirPath);
bool dumpArm7Overlay(const std::string& dirPath);
bool dumpArm7OverlayFiles(const std::string& dirPath);
bool dumpIconTitle(const std::string& dirPath);
bool dumpFatFiles(const std::string& dirPath);
bool dumpEverything(QString dirPath);
void populatePackerSectionHeader(NDSHeader *ndsHeader);
void enableCalcCrcButton();
void enableBuildRomButton();
void generateHeader(NDSHeader* pRomHeader);
bool writeHeader(const std::string& savePath);
void calcHeaderCrc16();
bool writeArm9Bin(const std::string& savePath, bool isArm9FooterPresent);
bool writeArm7Bin(const std::string& savePath);
bool writeFnt(const std::string& savePath);
bool writeFat(const std::string& savePath);
bool writeArm9Overlay(const std::string& savePath);
bool writeArm9OverlayFiles(const std::string& savePath);
bool writeArm7Overlay(const std::string& savePath);
bool writeArm7OverlayFiles(const std::string& savePath);
bool writeIconTitle(const std::string& savePath);
bool writeFatFiles(const std::string& savePath);
bool writeEverything(const std::string& savePath);
bool writeHeaderPadding(char paddingByte, const std::string& savePath);
bool writeArm9BinPadding(char paddingByte, const std::string& savePath, bool isArm9FooterPresent);
bool writeArm7BinPadding(char paddingByte, const std::string& savePath);
bool writeFntPadding(char paddingByte, const std::string& savePath);
bool writeFatPadding(char paddingByte, const std::string& savePath);
bool writeArm9OverlayPadding(char paddingByte, const std::string& savePath);
bool writeArm9OverlayFilesPadding(char paddingByte, const std::string& savePath);
bool writeArm7OverlayPadding(char paddingByte, const std::string& savePath);
bool writeArm7OverlayFilesPadding(char paddingByte, const std::string& savePath);
bool writeRomPadding(const std::string& savePath);
//QString extractUnpackerHeaderTableData(int index);
QString extractPackerHeaderTableData(int index);
bool decodeFatFiles(QString dirPath);
bool patchFat(const std::string& loadPath, uint32_t shiftSize, const std::string& savePath);
};
#endif // MAINWINDOW_H