2021-10-09 00:58:55 +02:00
|
|
|
#include <whb/log.h>
|
|
|
|
#include <whb/log_udp.h>
|
2022-07-26 08:16:27 +02:00
|
|
|
#include <whb/proc.h>
|
2021-10-09 00:58:55 +02:00
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
2021-10-15 15:41:16 +02:00
|
|
|
#include <coreinit/debug.h>
|
2021-10-16 13:03:32 +02:00
|
|
|
#include <coreinit/energysaver.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>
|
|
|
|
#include <iosuhax.h>
|
|
|
|
#include <ntfs.h>
|
|
|
|
#include <padscore/kpad.h>
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2021-10-15 15:41:16 +02:00
|
|
|
#include "MainApplicationState.h"
|
2022-07-26 08:16:27 +02:00
|
|
|
#include "input/VPADInput.h"
|
|
|
|
#include "utils/WiiUScreen.h"
|
|
|
|
#include "utils/logger.h"
|
2021-10-09 00:58:55 +02:00
|
|
|
|
2021-10-17 14:31:33 +02:00
|
|
|
|
2021-10-09 00:58:55 +02:00
|
|
|
void initIOSUHax();
|
|
|
|
|
|
|
|
void deInitIOSUHax();
|
|
|
|
|
|
|
|
void main_loop();
|
|
|
|
|
|
|
|
bool sIosuhaxMount = false;
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
WHBLogUdpInit();
|
|
|
|
DEBUG_FUNCTION_LINE("Hello from wudump!");
|
|
|
|
WHBProcInit();
|
|
|
|
WiiUScreen::Init();
|
|
|
|
|
|
|
|
initIOSUHax();
|
|
|
|
|
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();
|
|
|
|
|
2021-10-09 00:58:55 +02:00
|
|
|
main_loop();
|
|
|
|
|
2021-10-17 14:31:33 +02:00
|
|
|
WPADInput::close();
|
|
|
|
|
2021-10-09 00:58:55 +02:00
|
|
|
if (ntfs_mounts != nullptr) {
|
|
|
|
int i = 0;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-10-09 00:58:55 +02:00
|
|
|
deInitIOSUHax();
|
|
|
|
|
|
|
|
WiiUScreen::DeInit();
|
|
|
|
WHBProcShutdown();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (gFSAfd < 0 || !sIosuhaxMount) {
|
2021-10-15 15:41:16 +02:00
|
|
|
// state.setError(MainApplicationState::eErrorState::ERROR_IOSUHAX_FAILED);
|
|
|
|
OSFatal("IOSUHAX Failed");
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void initIOSUHax() {
|
|
|
|
sIosuhaxMount = false;
|
2022-07-26 08:16:27 +02:00
|
|
|
int res = IOSUHAX_Open(nullptr);
|
2021-10-09 00:58:55 +02:00
|
|
|
if (res < 0) {
|
|
|
|
DEBUG_FUNCTION_LINE("IOSUHAX_open failed");
|
|
|
|
} else {
|
|
|
|
sIosuhaxMount = true;
|
2022-07-26 08:16:27 +02:00
|
|
|
gFSAfd = IOSUHAX_FSA_Open();
|
2021-10-09 00:58:55 +02:00
|
|
|
if (gFSAfd < 0) {
|
|
|
|
DEBUG_FUNCTION_LINE("IOSUHAX_FSA_Open failed");
|
|
|
|
} else {
|
2021-10-15 15:41:16 +02:00
|
|
|
DEBUG_FUNCTION_LINE("IOSUHAX done");
|
2021-10-09 00:58:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void deInitIOSUHax() {
|
|
|
|
if (sIosuhaxMount) {
|
|
|
|
if (gFSAfd >= 0) {
|
|
|
|
IOSUHAX_FSA_Close(gFSAfd);
|
|
|
|
}
|
|
|
|
IOSUHAX_Close();
|
|
|
|
}
|
|
|
|
}
|