2017-03-30 20:11:37 +02:00
|
|
|
#include "Application.h"
|
2016-08-03 22:47:09 +02:00
|
|
|
#include "dynamic_libs/os_functions.h"
|
|
|
|
#include "dynamic_libs/gx2_functions.h"
|
|
|
|
#include "dynamic_libs/syshid_functions.h"
|
|
|
|
#include "dynamic_libs/vpad_functions.h"
|
|
|
|
#include "dynamic_libs/socket_functions.h"
|
|
|
|
#include "dynamic_libs/sys_functions.h"
|
2017-03-30 20:11:37 +02:00
|
|
|
#include "fs/fs_utils.h"
|
|
|
|
#include "fs/sd_fat_devoptab.h"
|
|
|
|
#include "system/memory.h"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "common/common.h"
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "common/common.h"
|
|
|
|
|
|
|
|
#include "controller_patcher/ControllerPatcher.hpp"
|
|
|
|
#include "controller_patcher/ConfigReader.hpp"
|
|
|
|
#include "controller_patcher/config/ConfigValues.hpp"
|
|
|
|
#include "controller_patcher/utils/CPRetainVars.hpp"
|
|
|
|
#include "controller_patcher/network/UDPServer.hpp"
|
|
|
|
#include "controller_patcher/network/TCPServer.hpp"
|
|
|
|
#include "utils/function_patcher.h"
|
|
|
|
#include "patcher/hid_controller_function_patcher.hpp"
|
2016-08-03 22:47:09 +02:00
|
|
|
#include "kernel/kernel_functions.h"
|
2017-03-30 20:11:37 +02:00
|
|
|
#include "kernel/syscalls.h"
|
2016-08-03 22:47:09 +02:00
|
|
|
#include "video/CursorDrawer.h"
|
|
|
|
#include "utils/logger.h"
|
2017-03-30 20:11:37 +02:00
|
|
|
#include "utils/StringTools.h"
|
2016-08-03 22:47:09 +02:00
|
|
|
|
2017-03-30 20:11:37 +02:00
|
|
|
#include "system/memory.h"
|
2016-08-03 22:47:09 +02:00
|
|
|
|
|
|
|
/* Entry point */
|
2017-03-30 20:11:37 +02:00
|
|
|
extern "C" int Menu_Main(void){
|
2016-08-03 22:47:09 +02:00
|
|
|
//!*******************************************************************
|
|
|
|
//! Initialize function pointers *
|
|
|
|
//!*******************************************************************
|
|
|
|
//! do OS (for acquire) and sockets first so we got logging
|
|
|
|
InitOSFunctionPointers();
|
2017-03-30 20:11:37 +02:00
|
|
|
InitFSFunctionPointers();
|
2016-08-03 22:47:09 +02:00
|
|
|
InitSocketFunctionPointers();
|
|
|
|
InitGX2FunctionPointers();
|
|
|
|
InitSysFunctionPointers();
|
|
|
|
InitVPadFunctionPointers();
|
2017-03-30 20:11:37 +02:00
|
|
|
InitPadScoreFunctionPointers();
|
|
|
|
InitAXFunctionPointers();
|
2016-08-03 22:47:09 +02:00
|
|
|
|
|
|
|
SetupKernelCallback();
|
|
|
|
|
|
|
|
log_init("192.168.0.181");
|
|
|
|
|
|
|
|
log_printf("HID to VPAD %s - %s %s - by Maschell\n\n",APP_VERION,__DATE__,__TIME__);
|
|
|
|
|
|
|
|
//!*******************************************************************
|
|
|
|
//! Initialize HID Config *
|
|
|
|
//!*******************************************************************
|
|
|
|
log_print("Initializing the controller data\n");
|
2017-03-30 20:11:37 +02:00
|
|
|
bool res = ControllerPatcher::Init();
|
|
|
|
if(!res){
|
|
|
|
SplashScreen(5, "Error. The app starts in 5 seconds without patches.");
|
|
|
|
RestorePatches();
|
|
|
|
return EXIT_RELAUNCH_ON_LOAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControllerPatcher::enableControllerMapping();
|
|
|
|
ControllerPatcher::startNetworkServer();
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
if(isInMiiMakerHBL()){
|
|
|
|
//!*******************************************************************
|
|
|
|
//! Initialize heap memory *
|
|
|
|
//!*******************************************************************
|
|
|
|
log_print("Initialize memory management\n");
|
|
|
|
memoryInitialize();
|
|
|
|
|
|
|
|
log_printf("Mount SD partition\n");
|
|
|
|
mount_sd_fat("sd");
|
|
|
|
log_printf("Start main application\n");
|
|
|
|
result = Application::instance()->exec();
|
|
|
|
|
|
|
|
log_printf("Main application stopped result: %d\n",result);
|
|
|
|
Application::destroyInstance();
|
|
|
|
log_printf("Unmount SD\n");
|
|
|
|
unmount_sd_fat("sd");
|
|
|
|
memoryRelease();
|
|
|
|
ControllerPatcher::destroyConfigHelper();
|
2016-08-03 22:47:09 +02:00
|
|
|
}
|
|
|
|
|
2017-03-30 20:11:37 +02:00
|
|
|
|
2016-08-03 22:47:09 +02:00
|
|
|
//!*******************************************************************
|
|
|
|
//! Patching functions *
|
|
|
|
//!*******************************************************************
|
|
|
|
log_print("Patching functions\n");
|
2017-03-30 20:11:37 +02:00
|
|
|
ApplyPatches();
|
2016-08-03 22:47:09 +02:00
|
|
|
|
2017-03-30 20:11:37 +02:00
|
|
|
if(!isInMiiMakerHBL()){
|
|
|
|
ControllerPatcher::disableWiiUEnergySetting();
|
2016-08-03 22:47:09 +02:00
|
|
|
return EXIT_RELAUNCH_ON_LOAD;
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:11:37 +02:00
|
|
|
if(result == APPLICATION_CLOSE_APPLY){
|
|
|
|
log_print("back to sysmenu\n");
|
2016-08-03 22:47:09 +02:00
|
|
|
SYSLaunchMenu();
|
|
|
|
return EXIT_RELAUNCH_ON_LOAD;
|
|
|
|
}
|
2017-03-30 20:11:37 +02:00
|
|
|
log_print("back to hbl\n");
|
|
|
|
ControllerPatcher::restoreWiiUEnergySetting();
|
2016-08-03 22:47:09 +02:00
|
|
|
deInit();
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:11:37 +02:00
|
|
|
void ApplyPatches(){
|
|
|
|
PatchInvidualMethodHooks( method_hooks_hid_controller, method_hooks_size_hid_controller, method_calls_hid_controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestorePatches(){
|
|
|
|
RestoreInvidualInstructions(method_hooks_hid_controller, method_hooks_size_hid_controller);
|
|
|
|
}
|
2016-08-03 22:47:09 +02:00
|
|
|
void deInit(){
|
|
|
|
CursorDrawer::destroyInstance();
|
2017-03-30 20:11:37 +02:00
|
|
|
RestorePatches();
|
|
|
|
ControllerPatcher::DeInit();
|
|
|
|
ControllerPatcher::stopNetworkServer();
|
2016-08-03 22:47:09 +02:00
|
|
|
log_deinit();
|
|
|
|
}
|
2017-03-30 20:11:37 +02:00
|
|
|
int isInMiiMakerHBL(){
|
|
|
|
if (OSGetTitleID != 0 && (
|
|
|
|
OSGetTitleID() == 0x000500101004A200 || // mii maker eur
|
|
|
|
OSGetTitleID() == 0x000500101004A100 || // mii maker usa
|
2017-03-31 16:54:16 +02:00
|
|
|
OSGetTitleID() == 0x000500101004A000 ||// mii maker jpn
|
2017-03-30 20:11:37 +02:00
|
|
|
OSGetTitleID() == 0x0005000013374842))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-03 22:47:09 +02:00
|
|
|
|
2017-03-30 20:11:37 +02:00
|
|
|
void SplashScreen(int time,char * message){
|
2016-08-03 22:47:09 +02:00
|
|
|
// Prepare screen
|
|
|
|
int screen_buf0_size = 0;
|
|
|
|
|
|
|
|
// Init screen and screen buffers
|
|
|
|
OSScreenInit();
|
|
|
|
screen_buf0_size = OSScreenGetBufferSizeEx(0);
|
|
|
|
OSScreenSetBufferEx(0, (void *)0xF4000000);
|
|
|
|
OSScreenSetBufferEx(1, (void *)(0xF4000000 + screen_buf0_size));
|
|
|
|
|
|
|
|
OSScreenEnableEx(0, 1);
|
|
|
|
OSScreenEnableEx(1, 1);
|
|
|
|
|
|
|
|
// Clear screens
|
|
|
|
OSScreenClearBufferEx(0, 0);
|
|
|
|
OSScreenClearBufferEx(1, 0);
|
|
|
|
|
|
|
|
// Flip buffers
|
|
|
|
OSScreenFlipBuffersEx(0);
|
|
|
|
OSScreenFlipBuffersEx(1);
|
|
|
|
|
2017-03-30 20:11:37 +02:00
|
|
|
OSScreenPutFontEx(0, 0, 0, message);
|
|
|
|
OSScreenPutFontEx(1, 0, 0, message);
|
2016-08-03 22:47:09 +02:00
|
|
|
|
|
|
|
OSScreenFlipBuffersEx(0);
|
|
|
|
OSScreenFlipBuffersEx(1);
|
|
|
|
|
|
|
|
int tickswait = time * 1000*1000;
|
|
|
|
int times = 1000;
|
|
|
|
int sleepingtime = tickswait / 1000;
|
2017-03-30 20:11:37 +02:00
|
|
|
int i=0;
|
2016-08-03 22:47:09 +02:00
|
|
|
while(i<times){
|
|
|
|
i++;
|
|
|
|
usleep(sleepingtime);
|
|
|
|
}
|
|
|
|
}
|