Skip to content

Commit

Permalink
Refactor menus and overall structure. NTFS only
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Oct 15, 2021
1 parent eb74e76 commit 47cca11
Show file tree
Hide file tree
Showing 24 changed files with 1,657 additions and 1,027 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ INCLUDES := include source
#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -g -Wall -O2 -ffunction-sections \
CFLAGS := -g -Wall -O0 -ffunction-sections \
$(MACHDEP)

CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
Expand Down
858 changes: 0 additions & 858 deletions source/ApplicationState.cpp

This file was deleted.

156 changes: 33 additions & 123 deletions source/ApplicationState.h
Original file line number Diff line number Diff line change
@@ -1,140 +1,50 @@
#pragma once

#include <map>
#include <string>
#include <optional>
#include <queue>
#include <coreinit/time.h>
#include "input/Input.h"
#include "fs/CFile.hpp"

#define SECTOR_SIZE 0x8000
#define READ_SECTOR_SIZE SECTOR_SIZE
#define READ_NUM_SECTORS 128
#define WRITE_BUFFER_NUM_SECTORS 128
#define WUD_FILE_SIZE 0x5D3A00000L


typedef struct {
unsigned int magic0;
unsigned int magic1;
unsigned int sectorSize;
unsigned long long uncompressedSize;
unsigned int flags;
} wuxHeader_t;

#define WUX_MAGIC_0 0x57555830
#define WUX_MAGIC_1 swap_uint32(0x1099d02e)
#include <utils/WiiUScreen.h>
#include <utils/ScreenUtils.h>

class ApplicationState {
public:

enum eDumpTargetFormat {
DUMP_AS_WUX,
DUMP_AS_WUD,
DUMP_AS_APP,
};


enum eErrorState {
ERROR_NONE,
ERROR_IOSUHAX_FAILED,
ERROR_OPEN_ODD1,
ERROR_READ_FIRST_SECTOR,
ERROR_FILE_OPEN_FAILED,
ERROR_MALLOC_FAILED,
ERROR_NO_DISC_ID,
ERROR_SECTOR_SIZE,
ERROR_MAGIC_NUMBER_WRONG,
ERROR_WRITE_FAILED,
};

enum eGameState {
STATE_ERROR,
STATE_WELCOME_SCREEN,
STATE_CHOOSE_TARGET,
STATE_OPEN_ODD1,
STATE_PLEASE_INSERT_DISC,
STATE_DUMP_APP_FILES,
STATE_DUMP_APP_FILES_DONE,
STATE_READ_DISC_INFO,
STATE_READ_DISC_INFO_DONE,
STATE_DUMP_DISC_KEY,
STATE_DUMP_DISC_START,
STATE_DUMP_DISC_DONE,
STATE_WAIT_USER_ERROR_CONFIRM,
STATE_DUMP_DISC,
enum eSubState {
SUBSTATE_RUNNING,
SUBSTATE_RETURN,
};

ApplicationState();

~ApplicationState();

void setError(eErrorState error);

void render();

void update(Input *input);

std::string ErrorMessage();

std::string ErrorDescription();

int selectedOption;

static void printFooter();

void proccessMenuNavigation(Input *input, int maxOptionValue);

static bool entrySelected(Input *input);

private:
static void printHeader();

CFile log;
eGameState state;
eDumpTargetFormat dumpFormat;
eErrorState error = ERROR_NONE;
std::string target = "fs:/vol/external01/";
int oddFd = -1;
int retryCount = 0;
void *sectorBuf = nullptr;
int sectorBufSize = READ_NUM_SECTORS * READ_SECTOR_SIZE;
char discId[11];
uint64_t currentSector = 0;
std::vector<uint64_t> skippedSectors;
int readResult = 0;

[[nodiscard]] bool writeDataToFile(void *buffer, int numberOfSection);

uint64_t totalSectorCount = 0;

std::map<std::string, int32_t> hashMap;
CFile *fileHandle;
OSTime startTime;
void *writeBuffer = nullptr;
uint32_t writeBufferPos = 0;
uint32_t writeBufferSize = 0;
virtual ~ApplicationState() = default;

[[nodiscard]] bool writeCached(uint32_t addr, uint32_t writeSize);
virtual void render() = 0;

void clearWriteCache();
virtual eSubState update(Input *input) = 0;

[[nodiscard]] bool flushWriteCache();
virtual void proccessMenuNavigation(Input *input, int32_t maxOptionValue) {
if (input->data.buttons_d & Input::BUTTON_UP) {
this->selectedOption--;
} else if (input->data.buttons_d & Input::BUTTON_DOWN) {
this->selectedOption++;
}
if (this->selectedOption < 0) {
this->selectedOption = maxOptionValue;
} else if (this->selectedOption >= maxOptionValue) {
this->selectedOption = 0;
}
}

uint32_t readSectors = 0;
uint64_t sectorTableStart = 0;
void *sectorIndexTable = nullptr;
uint64_t sectorTableEnd = 0;
virtual bool entrySelected(Input *input) {
return input->data.buttons_d & Input::BUTTON_A;
}

void writeSectorIndexTable();
virtual void printHeader() {
WiiUScreen::drawLine("Wudump");
WiiUScreen::drawLine("==================");
WiiUScreen::drawLine("");
}

void *emptySector = nullptr;
bool doWUX = false;
uint32_t writtenSector = 0;
bool autoSkip = false;
virtual void printFooter() {
ScreenUtils::printTextOnScreen(CONSOLE_SCREEN_TV, 0, 27, "By Maschell");
ScreenUtils::printTextOnScreen(CONSOLE_SCREEN_DRC, 0, 17, "By Maschell");
}

void dumpAppFiles();

static void printDumpState(const char *fmt, ...);
int selectedOption = 0;
};
Loading

0 comments on commit 47cca11

Please sign in to comment.