diff --git a/include/mocha/mocha.h b/include/mocha/mocha.h index f996aaf..34658b4 100644 --- a/include/mocha/mocha.h +++ b/include/mocha/mocha.h @@ -154,15 +154,6 @@ MochaUtilsStatus Mocha_GetEnvironmentPath(char *environmentPathBuffer, uint32_t */ MochaUtilsStatus Mocha_RPXHookCompleted(); -/** - * Starts the MCP thread of mocha to allows usage of /dev/iosuhax and wupclient - * @return MOCHA_RESULT_SUCCESS: Thread has been started
- * MOCHA_RESULT_LIB_UNINITIALIZED: Library was not initialized. Call Mocha_InitLibrary() before using this function.
- * MOCHA_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded mocha version.
- * MOCHA_RESULT_UNKNOWN_ERROR: Failed to retrieve the environment path. - */ -MochaUtilsStatus Mocha_StartMCPThread(); - /** * Enables logging via USB (FTDI FT232 chipset only) via OSReport and friends. * @param avoidLogCatchup If set to true, the log start at the moment this function is called (for the first time) diff --git a/source/devoptab/devoptab_fsa_seek.cpp b/source/devoptab/devoptab_fsa_seek.cpp index d59a6a9..182d891 100644 --- a/source/devoptab/devoptab_fsa_seek.cpp +++ b/source/devoptab/devoptab_fsa_seek.cpp @@ -58,15 +58,16 @@ off_t __fsa_seek(struct _reent *r, return -1; } + uint32_t old_pos = file->offset; + file->offset = offset + pos; + status = FSASetPosFile(deviceData->clientHandle, file->fd, file->offset); if (status < 0) { + file->offset = old_pos; DEBUG_FUNCTION_LINE_ERR("FSASetPosFile(0x%08X, 0x%08X, 0x%08X) failed: %s", deviceData->clientHandle, file->fd, file->offset, FSAGetStatusStr(status)); r->_errno = __fsa_translate_error(status); return -1; } - // Update the current offset - file->offset = offset + pos; - return file->offset; } diff --git a/source/utils.cpp b/source/utils.cpp index 6600134..93fcd9b 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -22,24 +22,34 @@ uint32_t mochaApiVersion = 0; #define IOCTL_CHECK_IF_IOSUHAX 0x5B #define IOSUHAX_MAGIC_WORD 0x4E696365 +MochaUtilsStatus Mocha_SimpleCommand(uint32_t command, uint32_t apiVersion); + MochaUtilsStatus Mocha_InitLibrary() { if (mochaInitDone) { return MOCHA_RESULT_SUCCESS; } if (iosuhaxHandle < 0) { - int haxHandle = IOS_Open((char *) ("/dev/iosuhax"), static_cast(0)); - if (haxHandle >= 0) { - ALIGN_0x40 int res[0x40 >> 2]; - *res = 0; - - IOS_Ioctl(haxHandle, IOCTL_CHECK_IF_IOSUHAX, (void *) nullptr, 0, res, 4); - if (*res != IOSUHAX_MAGIC_WORD) { - IOS_Close(haxHandle); - DEBUG_FUNCTION_LINE_ERR("Unexpected /dev/iosuhax magic"); - return MOCHA_RESULT_UNSUPPORTED_COMMAND; + auto res = MOCHA_RESULT_UNKNOWN_ERROR; + int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0); + if (mcpFd >= 0) { + ALIGN_0x40 uint32_t io_buffer[0x40 / 4]; + io_buffer[0] = IPC_CUSTOM_START_MCP_THREAD; + if (IOS_Ioctl(mcpFd, 100, io_buffer, 4, io_buffer, 0x4) == IOS_ERROR_OK) { + if (io_buffer[0] != 1) { // Thread is starting + OSSleepTicks(OSMillisecondsToTicks(50)); + } + res = MOCHA_RESULT_SUCCESS; } - } else { + + IOS_Close(mcpFd); + } + if (res != MOCHA_RESULT_SUCCESS) { + return res; + } + + int haxHandle = IOS_Open((char *) ("/dev/iosuhax"), static_cast(0)); + if (haxHandle < 0) { DEBUG_FUNCTION_LINE_ERR("Failed to open /dev/iosuhax"); return MOCHA_RESULT_UNSUPPORTED_COMMAND; } @@ -282,10 +292,6 @@ MochaUtilsStatus Mocha_RPXHookCompleted() { return Mocha_SimpleCommand(IPC_CUSTOM_MEN_RPX_HOOK_COMPLETED, 1); } -MochaUtilsStatus Mocha_StartMCPThread() { - return Mocha_SimpleCommand(IPC_CUSTOM_START_MCP_THREAD, 1); -} - MochaUtilsStatus Mocha_StartUSBLogging(bool avoidLogCatchup) { if (!mochaInitDone) { return MOCHA_RESULT_LIB_UNINITIALIZED;