diff --git a/source/GMPartitionsDumperState.cpp b/source/GMPartitionsDumperState.cpp index 7e8a14f..5ace115 100644 --- a/source/GMPartitionsDumperState.cpp +++ b/source/GMPartitionsDumperState.cpp @@ -37,7 +37,7 @@ GMPartitionsDumperState::GMPartitionsDumperState(eDumpTarget pTargetDevice) : ta GMPartitionsDumperState::~GMPartitionsDumperState() { if (this->oddFd != -1) { - FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd); + FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd); this->oddFd = -1; } free(this->sectorBuf); @@ -182,7 +182,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) { } if (this->state == STATE_OPEN_ODD1) { - auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &(this->oddFd)); + auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &(this->oddFd)); if (ret >= 0) { if (this->sectorBuf == nullptr) { this->sectorBuf = (void *) memalign(0x100, this->sectorBufSize); @@ -200,13 +200,13 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) { return ApplicationState::SUBSTATE_RETURN; } } else if (this->state == STATE_READ_DISC_INFO) { - if (FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) { + if (FSAEx_RawReadEx(gFSAClientHandle, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) { this->discId[10] = '\0'; memcpy(this->discId.data(), sectorBuf, 10); this->state = STATE_READ_DISC_INFO_DONE; return ApplicationState::SUBSTATE_RUNNING; } - FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd); + FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd); this->oddFd = -1; this->setError(ERROR_READ_FIRST_SECTOR); diff --git a/source/WUD/DiscReaderDiscDrive.cpp b/source/WUD/DiscReaderDiscDrive.cpp index 74e9b90..c759d39 100644 --- a/source/WUD/DiscReaderDiscDrive.cpp +++ b/source/WUD/DiscReaderDiscDrive.cpp @@ -31,13 +31,13 @@ DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() { return; } - auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &device_handle); + auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &device_handle); if (ret < 0) { free(sector_buf); return; } - auto res = FSAEx_RawRead(__wut_devoptab_fs_client, sector_buf, READ_SECTOR_SIZE, 1, 3, device_handle); + auto res = FSAEx_RawReadEx(gFSAClientHandle, sector_buf, READ_SECTOR_SIZE, 1, 3, device_handle); if (res >= 0) { if (((uint32_t *) sector_buf)[0] != WiiUDiscContentsHeader::MAGIC) { uint8_t iv[16]; @@ -75,7 +75,7 @@ DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() { } bool DiscReaderDiscDrive::readEncryptedSector(uint8_t *buffer, uint32_t block_cnt, uint32_t block_offset) const { - if (FSAEx_RawRead(__wut_devoptab_fs_client, buffer, READ_SECTOR_SIZE, block_cnt, block_offset, device_handle) < 0) { + if (FSAEx_RawReadEx(gFSAClientHandle, buffer, READ_SECTOR_SIZE, block_cnt, block_offset, device_handle) < 0) { return false; } return true; @@ -87,7 +87,7 @@ bool DiscReaderDiscDrive::IsReady() { DiscReaderDiscDrive::~DiscReaderDiscDrive() { if (device_handle != -1) { - FSAEx_RawClose(__wut_devoptab_fs_client, device_handle); + FSAEx_RawCloseEx(gFSAClientHandle, device_handle); device_handle = -1; } } @@ -102,7 +102,7 @@ bool DiscReaderDiscDrive::readEncrypted(uint8_t *buf, uint64_t offset, uint32_t } uint32_t block_cnt = size >> 15; uint32_t offset_in_sectors = offset >> 15; - if (FSAEx_RawRead(__wut_devoptab_fs_client, buf, 0x8000, block_cnt, offset_in_sectors, device_handle) < 0) { + if (FSAEx_RawReadEx(gFSAClientHandle, buf, 0x8000, block_cnt, offset_in_sectors, device_handle) < 0) { DEBUG_FUNCTION_LINE_ERR("Failed to read from Disc"); return false; } diff --git a/source/WUDDumperState.cpp b/source/WUDDumperState.cpp index 6ed5228..1a658d1 100644 --- a/source/WUDDumperState.cpp +++ b/source/WUDDumperState.cpp @@ -35,7 +35,7 @@ WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTargetFormat, WUDDumperState::~WUDDumperState() { if (this->oddFd >= 0) { - FSAEx_RawClose(__wut_devoptab_fs_client, oddFd); + FSAEx_RawCloseEx(gFSAClientHandle, oddFd); } free(sectorBuf); free(emptySector); @@ -51,7 +51,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { } if (this->state == STATE_OPEN_ODD1) { if (this->currentSector > 0) { - auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &(this->oddFd)); + auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &(this->oddFd)); if (ret >= 0) { // continue! this->state = STATE_DUMP_DISC; @@ -65,7 +65,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { this->state = STATE_PLEASE_INSERT_DISC; return ApplicationState::SUBSTATE_RUNNING; } - auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &(this->oddFd)); + auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &(this->oddFd)); if (ret >= 0) { if (this->sectorBuf == nullptr) { this->sectorBuf = (void *) memalign(0x100, this->sectorBufSize); @@ -83,7 +83,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { return SUBSTATE_RETURN; } } else if (this->state == STATE_READ_DISC_INFO) { - if (FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) { + if (FSAEx_RawReadEx(gFSAClientHandle, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) { this->discId[10] = '\0'; memcpy(this->discId.data(), sectorBuf, 10); this->state = STATE_READ_DISC_INFO_DONE; @@ -96,7 +96,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { this->state = STATE_DUMP_DISC_KEY; } else if (this->state == STATE_DUMP_DISC_KEY) { // Read the WiiUDiscContentsHeader to determine if we need disckey and if it's the correct one. - auto res = FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 3, this->oddFd); + auto res = FSAEx_RawReadEx(gFSAClientHandle, this->sectorBuf, READ_SECTOR_SIZE, 1, 3, this->oddFd); WUDDiscKey discKey; bool hasDiscKey = false; if (res >= 0) { @@ -151,7 +151,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { } size_t numSectors = this->currentSector + READ_NUM_SECTORS > this->totalSectorCount ? this->totalSectorCount - this->currentSector : READ_NUM_SECTORS; - if ((this->readResult = FSAEx_RawRead(__wut_devoptab_fs_client, sectorBuf, READ_SECTOR_SIZE, numSectors, this->currentSector, this->oddFd)) >= 0) { + if ((this->readResult = FSAEx_RawReadEx(gFSAClientHandle, sectorBuf, READ_SECTOR_SIZE, numSectors, this->currentSector, this->oddFd)) >= 0) { auto curWrittenSectors = fileHandle->writeSector((const uint8_t *) this->sectorBuf, numSectors); if (curWrittenSectors < 0) { this->setError(ERROR_WRITE_FAILED); @@ -180,7 +180,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { } else { this->state = STATE_WAIT_USER_ERROR_CONFIRM; if (this->oddFd >= 0) { - FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd); + FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd); this->oddFd = -1; } return ApplicationState::SUBSTATE_RUNNING; @@ -203,7 +203,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) { } else if (this->state == STATE_WAIT_USER_ERROR_CONFIRM) { if (this->autoSkipOnError) { if (this->oddFd >= 0) { - FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd); + FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd); this->oddFd = -1; } } diff --git a/source/common/common.cpp b/source/common/common.cpp index e897af4..9897e85 100644 --- a/source/common/common.cpp +++ b/source/common/common.cpp @@ -4,3 +4,4 @@ int ntfs_mount_count = 0; BOOL gRunFromHBL = false; BOOL gBlockHomeButton = false; uint32_t gBlockHomeButtonCooldown = 0; +FSAClientHandle gFSAClientHandle = 0; \ No newline at end of file diff --git a/source/common/common.h b/source/common/common.h index 8dd231b..2ad6d5e 100644 --- a/source/common/common.h +++ b/source/common/common.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -9,12 +10,13 @@ extern ntfs_md *ntfs_mounts; extern int ntfs_mount_count; -extern "C" FSClient *__wut_devoptab_fs_client; +extern FSAClientHandle gFSAClientHandle; extern BOOL gRunFromHBL; extern BOOL gBlockHomeButton; extern uint32_t gBlockHomeButtonCooldown; + enum eDumpTarget { TARGET_SD, TARGET_NTFS diff --git a/source/main.cpp b/source/main.cpp index d14bb52..27189d1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -53,9 +53,7 @@ int main(int argc, char **argv) { ProcUIClearCallbacks(); ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED, - &procHomeButtonDeniedCustom, NULL, 100); - - + &procHomeButtonDeniedCustom, nullptr, 100); } else { gRunFromHBL = false; } @@ -76,8 +74,19 @@ int main(int argc, char **argv) { WPADInput::init(); + gFSAClientHandle = FSAAddClient(nullptr); + if (!gFSAClientHandle) { + OSFatal("FSAAddClient failed"); + } + + if (Mocha_UnlockFSClientEx(gFSAClientHandle) != MOCHA_RESULT_SUCCESS) { + OSFatal("Failed to unlock FSAClientHandle"); + } + main_loop(); + FSADelClient(gFSAClientHandle); + WPADInput::close(); if (ntfs_mounts != nullptr) {