mirror of
https://github.com/wiiu-env/libmocha.git
synced 2024-09-28 19:28:36 +02:00
Fix Mocha_InitLibrary(), fix seek
This commit is contained in:
parent
41226ab3ca
commit
8b3cbc8ad5
@ -154,15 +154,6 @@ MochaUtilsStatus Mocha_GetEnvironmentPath(char *environmentPathBuffer, uint32_t
|
|||||||
*/
|
*/
|
||||||
MochaUtilsStatus Mocha_RPXHookCompleted();
|
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<br>
|
|
||||||
* MOCHA_RESULT_LIB_UNINITIALIZED: Library was not initialized. Call Mocha_InitLibrary() before using this function.<br>
|
|
||||||
* MOCHA_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded mocha version.<br>
|
|
||||||
* 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.
|
* 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)
|
* @param avoidLogCatchup If set to true, the log start at the moment this function is called (for the first time)
|
||||||
|
@ -58,15 +58,16 @@ off_t __fsa_seek(struct _reent *r,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t old_pos = file->offset;
|
||||||
|
file->offset = offset + pos;
|
||||||
|
|
||||||
status = FSASetPosFile(deviceData->clientHandle, file->fd, file->offset);
|
status = FSASetPosFile(deviceData->clientHandle, file->fd, file->offset);
|
||||||
if (status < 0) {
|
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));
|
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);
|
r->_errno = __fsa_translate_error(status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the current offset
|
|
||||||
file->offset = offset + pos;
|
|
||||||
|
|
||||||
return file->offset;
|
return file->offset;
|
||||||
}
|
}
|
||||||
|
@ -22,24 +22,34 @@ uint32_t mochaApiVersion = 0;
|
|||||||
#define IOCTL_CHECK_IF_IOSUHAX 0x5B
|
#define IOCTL_CHECK_IF_IOSUHAX 0x5B
|
||||||
#define IOSUHAX_MAGIC_WORD 0x4E696365
|
#define IOSUHAX_MAGIC_WORD 0x4E696365
|
||||||
|
|
||||||
|
MochaUtilsStatus Mocha_SimpleCommand(uint32_t command, uint32_t apiVersion);
|
||||||
|
|
||||||
MochaUtilsStatus Mocha_InitLibrary() {
|
MochaUtilsStatus Mocha_InitLibrary() {
|
||||||
if (mochaInitDone) {
|
if (mochaInitDone) {
|
||||||
return MOCHA_RESULT_SUCCESS;
|
return MOCHA_RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iosuhaxHandle < 0) {
|
if (iosuhaxHandle < 0) {
|
||||||
int haxHandle = IOS_Open((char *) ("/dev/iosuhax"), static_cast<IOSOpenMode>(0));
|
auto res = MOCHA_RESULT_UNKNOWN_ERROR;
|
||||||
if (haxHandle >= 0) {
|
int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0);
|
||||||
ALIGN_0x40 int res[0x40 >> 2];
|
if (mcpFd >= 0) {
|
||||||
*res = 0;
|
ALIGN_0x40 uint32_t io_buffer[0x40 / 4];
|
||||||
|
io_buffer[0] = IPC_CUSTOM_START_MCP_THREAD;
|
||||||
IOS_Ioctl(haxHandle, IOCTL_CHECK_IF_IOSUHAX, (void *) nullptr, 0, res, 4);
|
if (IOS_Ioctl(mcpFd, 100, io_buffer, 4, io_buffer, 0x4) == IOS_ERROR_OK) {
|
||||||
if (*res != IOSUHAX_MAGIC_WORD) {
|
if (io_buffer[0] != 1) { // Thread is starting
|
||||||
IOS_Close(haxHandle);
|
OSSleepTicks(OSMillisecondsToTicks(50));
|
||||||
DEBUG_FUNCTION_LINE_ERR("Unexpected /dev/iosuhax magic");
|
|
||||||
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
|
|
||||||
}
|
}
|
||||||
} else {
|
res = MOCHA_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
IOS_Close(mcpFd);
|
||||||
|
}
|
||||||
|
if (res != MOCHA_RESULT_SUCCESS) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int haxHandle = IOS_Open((char *) ("/dev/iosuhax"), static_cast<IOSOpenMode>(0));
|
||||||
|
if (haxHandle < 0) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to open /dev/iosuhax");
|
DEBUG_FUNCTION_LINE_ERR("Failed to open /dev/iosuhax");
|
||||||
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
|
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
|
||||||
}
|
}
|
||||||
@ -282,10 +292,6 @@ MochaUtilsStatus Mocha_RPXHookCompleted() {
|
|||||||
return Mocha_SimpleCommand(IPC_CUSTOM_MEN_RPX_HOOK_COMPLETED, 1);
|
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) {
|
MochaUtilsStatus Mocha_StartUSBLogging(bool avoidLogCatchup) {
|
||||||
if (!mochaInitDone) {
|
if (!mochaInitDone) {
|
||||||
return MOCHA_RESULT_LIB_UNINITIALIZED;
|
return MOCHA_RESULT_LIB_UNINITIALIZED;
|
||||||
|
Loading…
Reference in New Issue
Block a user