2022-07-26 09:24:06 +02:00
|
|
|
#include "MainApplicationState.h"
|
|
|
|
#include "input/VPADInput.h"
|
|
|
|
#include "utils/WiiUScreen.h"
|
|
|
|
#include "utils/logger.h"
|
2021-10-15 15:41:16 +02:00
|
|
|
#include <coreinit/debug.h>
|
2021-10-16 13:03:32 +02:00
|
|
|
#include <coreinit/energysaver.h>
|
2022-07-26 14:27:31 +02:00
|
|
|
#include <coreinit/title.h>
|
2021-10-17 15:09:53 +02:00
|
|
|
#include <input/CombinedInput.h>
|
2022-07-26 08:16:27 +02:00
|
|
|
#include <input/WPADInput.h>
|
2022-07-26 09:24:06 +02:00
|
|
|
#include <mocha/disc_interface.h>
|
|
|
|
#include <mocha/mocha.h>
|
2022-07-26 08:16:27 +02:00
|
|
|
#include <ntfs.h>
|
|
|
|
#include <padscore/kpad.h>
|
2023-01-10 16:26:21 +01:00
|
|
|
#include <sndcore2/core.h>
|
2022-07-26 09:24:06 +02:00
|
|
|
#include <thread>
|
|
|
|
#include <whb/log.h>
|
|
|
|
#include <whb/proc.h>
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
void initMochaLib();
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
void deInitMochaLib();
|
2021-10-17 14:31:33 +02:00
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
void main_loop();
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
bool slibMochaMount = false;
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
extern "C" void ACPInitialize();
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
static uint32_t
|
|
|
|
procHomeButtonDeniedCustom(void *context) {
|
|
|
|
if (!gBlockHomeButton && gRunFromHBL) {
|
|
|
|
WHBProcStopRunning();
|
|
|
|
} else {
|
|
|
|
gBlockHomeButtonCooldown = 5;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2021-10-09 00:58:55 +02:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2022-07-26 09:24:06 +02:00
|
|
|
initLogging();
|
2021-10-09 00:58:55 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Hello from wudump!");
|
2023-01-10 16:26:21 +01:00
|
|
|
AXInit();
|
2021-10-09 00:58:55 +02:00
|
|
|
WHBProcInit();
|
|
|
|
WiiUScreen::Init();
|
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
initMochaLib();
|
|
|
|
ACPInitialize();
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2022-07-26 14:27:31 +02:00
|
|
|
uint64_t titleID = OSGetTitleID();
|
|
|
|
if (titleID == 0x0005000013374842 ||
|
|
|
|
titleID == 0x000500101004A000 ||
|
|
|
|
titleID == 0x000500101004A100 ||
|
|
|
|
titleID == 0x000500101004A200) {
|
|
|
|
gRunFromHBL = true;
|
2022-07-26 09:24:06 +02:00
|
|
|
|
|
|
|
ProcUIClearCallbacks();
|
|
|
|
ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED,
|
2022-08-02 10:25:12 +02:00
|
|
|
&procHomeButtonDeniedCustom, nullptr, 100);
|
2022-07-26 14:27:31 +02:00
|
|
|
} else {
|
|
|
|
gRunFromHBL = false;
|
|
|
|
}
|
|
|
|
|
2021-10-16 13:03:32 +02:00
|
|
|
uint32_t isAPDEnabled;
|
|
|
|
IMIsAPDEnabled(&isAPDEnabled);
|
|
|
|
|
|
|
|
if (isAPDEnabled) {
|
|
|
|
DEBUG_FUNCTION_LINE("Disable auto shutdown");
|
|
|
|
IMDisableAPD();
|
|
|
|
}
|
|
|
|
|
2021-10-09 00:58:55 +02:00
|
|
|
ntfs_mount_count = ntfsMountAll((ntfs_md **) &ntfs_mounts, NTFS_DEFAULT | NTFS_RECOVER);
|
|
|
|
|
|
|
|
for (int i = 0; i < ntfs_mount_count; i++) {
|
|
|
|
DEBUG_FUNCTION_LINE("%s:", ntfs_mounts[i].name);
|
|
|
|
}
|
|
|
|
|
2021-10-17 14:31:33 +02:00
|
|
|
WPADInput::init();
|
|
|
|
|
2022-08-02 10:25:12 +02:00
|
|
|
gFSAClientHandle = FSAAddClient(nullptr);
|
|
|
|
if (!gFSAClientHandle) {
|
|
|
|
OSFatal("FSAAddClient failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Mocha_UnlockFSClientEx(gFSAClientHandle) != MOCHA_RESULT_SUCCESS) {
|
|
|
|
OSFatal("Failed to unlock FSAClientHandle");
|
|
|
|
}
|
|
|
|
|
2021-10-09 00:58:55 +02:00
|
|
|
main_loop();
|
|
|
|
|
2022-08-02 10:25:12 +02:00
|
|
|
FSADelClient(gFSAClientHandle);
|
|
|
|
|
2021-10-17 14:31:33 +02:00
|
|
|
WPADInput::close();
|
|
|
|
|
2021-10-09 00:58:55 +02:00
|
|
|
if (ntfs_mounts != nullptr) {
|
2022-07-26 09:24:06 +02:00
|
|
|
int i;
|
2021-10-09 00:58:55 +02:00
|
|
|
for (i = 0; i < ntfs_mount_count; i++) {
|
|
|
|
ntfsUnmount(ntfs_mounts[i].name, true);
|
|
|
|
}
|
|
|
|
free(ntfs_mounts);
|
|
|
|
}
|
|
|
|
|
2021-10-16 13:03:32 +02:00
|
|
|
if (isAPDEnabled) {
|
|
|
|
DEBUG_FUNCTION_LINE("Enable auto shutdown");
|
|
|
|
IMEnableAPD();
|
|
|
|
}
|
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
deInitMochaLib();
|
2021-10-09 00:58:55 +02:00
|
|
|
|
|
|
|
WiiUScreen::DeInit();
|
|
|
|
WHBProcShutdown();
|
2023-01-10 16:26:21 +01:00
|
|
|
AXQuit();
|
2021-10-09 00:58:55 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main_loop() {
|
|
|
|
DEBUG_FUNCTION_LINE("Creating state");
|
2021-10-15 15:41:16 +02:00
|
|
|
std::unique_ptr<MainApplicationState> state = std::make_unique<MainApplicationState>();
|
2021-10-17 15:09:53 +02:00
|
|
|
CombinedInput baseInput;
|
2021-10-17 14:31:33 +02:00
|
|
|
VPadInput vpadInput;
|
|
|
|
WPADInput wpadInputs[4] = {
|
|
|
|
WPAD_CHAN_0,
|
|
|
|
WPAD_CHAN_1,
|
|
|
|
WPAD_CHAN_2,
|
2022-07-26 08:16:27 +02:00
|
|
|
WPAD_CHAN_3};
|
2021-10-09 00:58:55 +02:00
|
|
|
|
|
|
|
DEBUG_FUNCTION_LINE("Entering main loop");
|
|
|
|
while (WHBProcIsRunning()) {
|
2021-10-17 15:09:53 +02:00
|
|
|
baseInput.reset();
|
|
|
|
if (vpadInput.update(1280, 720)) {
|
|
|
|
baseInput.combine(vpadInput);
|
2021-10-17 14:31:33 +02:00
|
|
|
}
|
2022-07-26 08:16:27 +02:00
|
|
|
for (auto &wpadInput : wpadInputs) {
|
|
|
|
if (wpadInput.update(1280, 720)) {
|
2021-10-17 15:09:53 +02:00
|
|
|
baseInput.combine(wpadInput);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
baseInput.process();
|
|
|
|
state->update(&baseInput);
|
2021-10-15 15:41:16 +02:00
|
|
|
state->render();
|
2021-10-09 00:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
void initMochaLib() {
|
|
|
|
slibMochaMount = false;
|
|
|
|
MochaUtilsStatus res = Mocha_InitLibrary();
|
|
|
|
if (res != MOCHA_RESULT_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Mocha_InitLibrary failed: %s", Mocha_GetStatusStr(res));
|
|
|
|
OSFatal("Failed to init libmocha. Please update MochaPayload.");
|
2021-10-09 00:58:55 +02:00
|
|
|
} else {
|
2022-07-26 09:24:06 +02:00
|
|
|
slibMochaMount = true;
|
2021-10-09 00:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 09:24:06 +02:00
|
|
|
void deInitMochaLib() {
|
|
|
|
if (slibMochaMount) {
|
2023-01-10 16:19:43 +01:00
|
|
|
Mocha_DeInitLibrary();
|
2021-10-09 00:58:55 +02:00
|
|
|
}
|
2022-07-26 09:24:06 +02:00
|
|
|
|
|
|
|
Mocha_sdio_disc_interface.shutdown();
|
|
|
|
Mocha_usb_disc_interface.shutdown();
|
2021-10-09 00:58:55 +02:00
|
|
|
}
|