#include <stdint.h>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <coreinit/mcp.h>
#include <sysapp/launch.h>
#include <whb/log.h>
#include <whb/log_udp.h>
#include <whb/proc.h>
#include <wut_structsize.h>
extern void _SYSLaunchTitleWithStdArgsInNoSplash(uint64_t, int);
typedef struct WUT_PACKED
{
uint32_t cmd;
uint32_t tgt;
uint32_t fs;
uint32_t fo;
char path[256];
} LOAD_REQUEST;
WUT_CHECK_OFFSET(LOAD_REQUEST, 0x00, cmd);
WUT_CHECK_OFFSET(LOAD_REQUEST, 0x04, tgt);
WUT_CHECK_OFFSET(LOAD_REQUEST, 0x08, fs);
WUT_CHECK_OFFSET(LOAD_REQUEST, 0x0C, fo);
WUT_CHECK_OFFSET(LOAD_REQUEST, 0x10, path);
WUT_CHECK_SIZE(LOAD_REQUEST, 0x110);
const uint64_t hs[3] = { 0x000500101004E000, 0x000500101004E100, 0x000500101004E200 };
const LOAD_REQUEST request =
{
.cmd = 0xFC,
.tgt = 0,
.fs = 0,
.fo = 0,
.path = "wiiu/apps/[TODO].rpx",
};
void *reqPtr = (void *)&request;
int main()
{
WHBProcInit();
WHBLogUdpInit();
WHBLogPrint("RetroArch loader");
int mcpHandle = MCP_Open();
if(mcpHandle > 0)
{
WHBLogPrint("Sending request");
DCFlushRange(reqPtr, sizeof(LOAD_REQUEST));
IOS_Ioctl(mcpHandle, 100, reqPtr, sizeof(LOAD_REQUEST), NULL, 0);
uint64_t tid = 0;
MCPTitleListType tlt;
for(int i = 0; i < 3; ++i)
{
if(MCP_GetTitleInfo(mcpHandle, hs[i], &tlt) == 0)
{
tid = hs[i];
break;
}
}
MCP_Close(mcpHandle);
if(tid)
{
WHBLogPrint("Sending relaunch request");
_SYSLaunchTitleWithStdArgsInNoSplash(tid, 0);
WHBLogPrint("Returning");
WHBLogUdpDeinit();
WHBProcStopRunning();
WHBProcIsRunning();
return 0;
}
}
SYSLaunchMenu();
WHBLogPrint("Returning with error");
WHBLogUdpDeinit();
WHBProcStopRunning();
WHBProcIsRunning();
return 0;
}