Skip to content

Commit

Permalink
Add support for Haxchi/CBHC
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpl0itU committed Jun 23, 2022
1 parent b145f0f commit d2c3656
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
6 changes: 6 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
#include <algorithm>
#include <array>

#include <coreinit/ios.h>
#include <coreinit/mcp.h>
#include <coreinit/thread.h>
#include <coreinit/time.h>
#include <coreinit/screen.h>
#include <padscore/kpad.h>
#include <sysapp/launch.h>
#include <sysapp/title.h>
#include <vpad/input.h>
#include <whb/proc.h>
56 changes: 47 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@ static int cursorb = 0, cursort = 0, scrollb = 0;
static int titleswiiu = 0, titlesvwii = 0;
static const std::array<const char *, 4> sortn = {"None", "Name", "Storage", "Storage+Name"};

void someFunc(IOSError err, void *arg){(void)arg;}

int mcp_hook_fd = -1;
int MCPHookOpen()
{
//take over mcp thread
mcp_hook_fd = MCP_Open();
if(mcp_hook_fd < 0)
return -1;
IOS_IoctlAsync(mcp_hook_fd, 0x62, (void*)0, 0, (void*)0, 0, someFunc, (void*)0);
//let wupserver start up
OSSleepTicks(OSMillisecondsToTicks(500));
if(IOSUHAX_Open("/dev/mcp") < 0)
return -1;
return 0;
}

void MCPHookClose()
{
if(mcp_hook_fd < 0)
return;
//close down wupserver, return control to mcp
IOSUHAX_Close();
//wait for mcp to return
OSSleepTicks(OSMillisecondsToTicks(500));
MCP_Close(mcp_hook_fd);
mcp_hook_fd = -1;
}

template<class It>
static void sortTitle(It titles, It last, int tsort = 1, int sorta = 1) {
switch (tsort) {
Expand Down Expand Up @@ -417,11 +446,14 @@ auto main() -> int {
loadWiiUTitles(0);

int res = IOSUHAX_Open(NULL);
if (res < 0) {
promptError("IOSUHAX_Open failed.");
flipBuffers();
WHBProcShutdown();
return 0;
if (res < 0) { // Not Tiramisu/Mocha
res = MCPHookOpen();
if (res < 0) {
promptError("IOSUHAX_Open failed.");
flipBuffers();
WHBProcShutdown();
return 0;
}
}

int fsaFd = IOSUHAX_FSA_Open();
Expand Down Expand Up @@ -1098,16 +1130,22 @@ auto main() -> int {
unloadTitles(wiititles, titlesvwii);
free(versionList);

OSScreenShutdown();
WHBLogFreetypeFree();
WHBProcShutdown();
fatUnmount("sd");
unmount_fs("slc");
unmount_fs("mlc");
unmount_fs("usb");

IOSUHAX_FSA_Close(fsaFd);
IOSUHAX_Close();
if(mcp_hook_fd >= 0) {
MCPHookClose();
SYSRelaunchTitle(0, NULL);
} else {
IOSUHAX_Close();
}

OSScreenShutdown();
WHBLogFreetypeFree();
WHBProcShutdown();

return 0;
}

0 comments on commit d2c3656

Please sign in to comment.