From 5e01fb7d3f458fafa4f7e321f963eecd05e89874 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 30 Mar 2017 17:51:11 +0200 Subject: [PATCH] Added WPAD and socket functions --- acp_functions.c | 2 +- acp_functions.h | 2 +- aoc_functions.c | 2 +- aoc_functions.h | 2 +- ax_functions.c | 2 +- ax_functions.h | 2 +- curl_functions.c | 2 +- gx2_functions.c | 2 +- os_functions.c | 6 +++++- os_functions.h | 6 ++++-- padscore_functions.c | 2 +- padscore_functions.h | 30 +++++++++++++++++++++++++++++- socket_functions.c | 19 ++++++++++++++++++- socket_functions.h | 2 +- sys_functions.c | 2 +- sys_functions.h | 2 +- syshid_functions.c | 2 +- syshid_functions.h | 2 +- vpad_functions.c | 4 ++-- vpad_functions.h | 4 ++-- 20 files changed, 74 insertions(+), 23 deletions(-) diff --git a/acp_functions.c b/acp_functions.c index eb931f8..beed06a 100644 --- a/acp_functions.c +++ b/acp_functions.c @@ -24,7 +24,7 @@ #include "os_functions.h" #include "acp_functions.h" -unsigned int acp_handle __attribute__((section(".data"))) = 0; +u32 acp_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(void, GetMetaXml, void * _ACPMetaXml); diff --git a/acp_functions.h b/acp_functions.h index dc1822d..328b9c3 100644 --- a/acp_functions.h +++ b/acp_functions.h @@ -30,7 +30,7 @@ extern "C" { #include -extern unsigned int acp_handle; +extern u32 acp_handle; void InitACPFunctionPointers(void); void InitAcquireACP(void); diff --git a/aoc_functions.c b/aoc_functions.c index e74306d..e1adc7a 100644 --- a/aoc_functions.c +++ b/aoc_functions.c @@ -24,7 +24,7 @@ #include "os_functions.h" #include "aoc_functions.h" -unsigned int aoc_handle __attribute__((section(".data"))) = 0; +u32 aoc_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(s32, AOC_Initialize, void); EXPORT_DECL(s32, AOC_Finalize, void); diff --git a/aoc_functions.h b/aoc_functions.h index efca771..79a95d4 100644 --- a/aoc_functions.h +++ b/aoc_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -extern unsigned int aoc_handle; +extern u32 aoc_handle; #define AOC_TITLE_SIZE 104 diff --git a/ax_functions.c b/ax_functions.c index e517f6d..2333d0a 100644 --- a/ax_functions.c +++ b/ax_functions.c @@ -25,7 +25,7 @@ #include "os_functions.h" #include "ax_functions.h" -unsigned int sound_handle __attribute__((section(".data"))) = 0; +u32 sound_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(void, AXInitWithParams, u32 * params); EXPORT_DECL(void, AXInit, void); diff --git a/ax_functions.h b/ax_functions.h index 086346f..206d34f 100644 --- a/ax_functions.h +++ b/ax_functions.h @@ -30,7 +30,7 @@ extern "C" { #include -extern unsigned int sound_handle; +extern u32 sound_handle; void InitAXFunctionPointers(void); void InitAcquireAX(void); diff --git a/curl_functions.c b/curl_functions.c index d828cdb..0c2988e 100644 --- a/curl_functions.c +++ b/curl_functions.c @@ -24,7 +24,7 @@ #include "os_functions.h" #include "curl_functions.h" -unsigned int libcurl_handle __attribute__((section(".data"))) = 0; +u32 libcurl_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(CURLcode, n_curl_global_init, long flags); EXPORT_DECL(CURL *, n_curl_easy_init, void); diff --git a/gx2_functions.c b/gx2_functions.c index a34807e..e491ba9 100644 --- a/gx2_functions.c +++ b/gx2_functions.c @@ -24,7 +24,7 @@ #include "os_functions.h" #include "gx2_types.h" -unsigned int gx2_handle __attribute__((section(".data"))) = 0; +u32 gx2_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(void, GX2Init, u32 * init_attribs); EXPORT_DECL(void, GX2Shutdown, void); diff --git a/os_functions.c b/os_functions.c index 46608b2..3a4f9c3 100644 --- a/os_functions.c +++ b/os_functions.c @@ -24,7 +24,7 @@ #include "common/common.h" #include "os_functions.h" -unsigned int coreinit_handle __attribute__((section(".data"))) = 0; +u32 coreinit_handle __attribute__((section(".data"))) = 0; //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Lib handle functions @@ -139,6 +139,8 @@ EXPORT_DECL(int, IMDisableAPD,void); EXPORT_DECL(int, IMIsAPDEnabled,int * result); EXPORT_DECL(int, IMIsAPDEnabledBySysSettings,int * result); +EXPORT_DECL(s32, OSSendAppSwitchRequest,int param,void* unknown1,void* unknown2); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! IOS functions //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- @@ -254,6 +256,8 @@ void InitOSFunctionPointers(void) OS_FIND_EXPORT(coreinit_handle, IMIsAPDEnabled); OS_FIND_EXPORT(coreinit_handle, IMIsAPDEnabledBySysSettings); + OS_FIND_EXPORT(coreinit_handle, OSSendAppSwitchRequest); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! IOS functions //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/os_functions.h b/os_functions.h index 5d7aa2d..27834b0 100644 --- a/os_functions.h +++ b/os_functions.h @@ -65,7 +65,7 @@ extern "C" { #define OS_MUTEX_SIZE 44 /* Handle for coreinit */ -extern unsigned int coreinit_handle; +extern u32 coreinit_handle; void InitOSFunctionPointers(void); void InitAcquireOS(void); @@ -167,10 +167,12 @@ extern int (*IMDisableAPD)(void); extern int (*IMIsAPDEnabled)(int * result); extern int (*IMIsAPDEnabledBySysSettings)(int * result); +extern s32 (*OSSendAppSwitchRequest)(int param,void* unknown1,void* unknown2); + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! IOS functions //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - + extern int (*IOS_Ioctl)(int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len); extern int (*IOS_Open)(char *path, unsigned int mode); extern int (*IOS_Close)(int fd); diff --git a/padscore_functions.c b/padscore_functions.c index f7ca8e9..c9048b4 100644 --- a/padscore_functions.c +++ b/padscore_functions.c @@ -24,7 +24,7 @@ #include "os_functions.h" #include "padscore_functions.h" -unsigned int padscore_handle __attribute__((section(".data"))) = 0; +u32 padscore_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(void, KPADInit, void); EXPORT_DECL(void, WPADInit, void); diff --git a/padscore_functions.h b/padscore_functions.h index 5b000b1..f126557 100644 --- a/padscore_functions.h +++ b/padscore_functions.h @@ -30,10 +30,20 @@ extern "C" { #include "dynamic_libs/vpad_functions.h" -extern unsigned int padscore_handle; +extern u32 padscore_handle; #include +#define WPAD_EXT_CORE 0 +#define WPAD_EXT_NUNCHUK 1 +#define WPAD_EXT_CLASSIC 2 +#define WPAD_EXT_MPLUS 5 +#define WPAD_EXT_MPLUS_NUNCHUK 6 +#define WPAD_EXT_MPLUS_CLASSIC 7 +#define WPAD_EXT_PRO_CONTROLLER 31 + +#define WPAD_FMT_PRO_CONTROLLER 22 + #define WPAD_BUTTON_LEFT 0x0001 #define WPAD_BUTTON_RIGHT 0x0002 #define WPAD_BUTTON_DOWN 0x0004 @@ -148,9 +158,27 @@ typedef struct _KPADData }; u32 unused_7[16]; } KPADData; + +typedef struct WPADReadData_ { + u8 unknown[40]; + u8 dev; + u8 err; + u8 unknown1[2]; + u32 buttons; + s16 l_stick_x; + s16 l_stick_y; + s16 r_stick_x; + s16 r_stick_y; + u8 unknown2[8]; + u8 fmt; +}WPADReadData; + +typedef WPADReadData KPADUnifiedWpadData; + void InitPadScoreFunctionPointers(void); void InitAcquirePadScore(void); +typedef void (* wpad_extension_callback_t)(s32 chan, s32 status); typedef void (* wpad_connect_callback_t)(s32 chan, s32 status); extern void (* KPADInit)(void); diff --git a/socket_functions.c b/socket_functions.c index de2c31f..d222b2a 100644 --- a/socket_functions.c +++ b/socket_functions.c @@ -26,7 +26,7 @@ u32 hostIpAddress = 0; -unsigned int nsysnet_handle __attribute__((section(".data"))) = 0; +u32 nsysnet_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(void, socket_lib_init, void); EXPORT_DECL(int, socket, int domain, int type, int protocol); @@ -58,6 +58,17 @@ void InitSocketFunctionPointers(void) InitAcquireSocket(); + unsigned int nn_ac_handle; + int(*ACInitialize)(); + int(*ACGetStartupId) (unsigned int *id); + int(*ACConnectWithConfigId) (unsigned int id); + int(*ACGetAssignedAddress) (u32 * ip); + OSDynLoad_Acquire("nn_ac.rpl", &nn_ac_handle); + OSDynLoad_FindExport(nn_ac_handle, 0, "ACInitialize", &ACInitialize); + OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetStartupId", &ACGetStartupId); + OSDynLoad_FindExport(nn_ac_handle, 0, "ACConnectWithConfigId",&ACConnectWithConfigId); + OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetAssignedAddress",&ACGetAssignedAddress); + OS_FIND_EXPORT(nsysnet_handle, socket_lib_init); OS_FIND_EXPORT(nsysnet_handle, socket); OS_FIND_EXPORT(nsysnet_handle, socketclose); @@ -77,5 +88,11 @@ void InitSocketFunctionPointers(void) OS_FIND_EXPORT(nsysnet_handle, NSSLRead); OS_FIND_EXPORT(nsysnet_handle, NSSLCreateConnection); + unsigned int nn_startupid; + ACInitialize(); + ACGetStartupId(&nn_startupid); + ACConnectWithConfigId(nn_startupid); + ACGetAssignedAddress(&hostIpAddress); + socket_lib_init(); } diff --git a/socket_functions.h b/socket_functions.h index 1e4df1a..02acfd7 100644 --- a/socket_functions.h +++ b/socket_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -extern unsigned int nsysnet_handle; +extern u32 nsysnet_handle; #include diff --git a/sys_functions.c b/sys_functions.c index c054549..22aaec1 100644 --- a/sys_functions.c +++ b/sys_functions.c @@ -23,7 +23,7 @@ ***************************************************************************/ #include "os_functions.h" - unsigned int sysapp_handle __attribute__((section(".data"))) = 0; +u32 sysapp_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(int, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero); EXPORT_DECL(int, SYSRelaunchTitle, int argc, char** argv); diff --git a/sys_functions.h b/sys_functions.h index 08ca21b..dad1e2e 100644 --- a/sys_functions.h +++ b/sys_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -extern unsigned int sysapp_handle; +extern u32 sysapp_handle; void InitSysFunctionPointers(void); void InitAcquireSys(void); diff --git a/syshid_functions.c b/syshid_functions.c index 996d39d..53e02c9 100644 --- a/syshid_functions.c +++ b/syshid_functions.c @@ -24,7 +24,7 @@ #include "os_functions.h" #include "syshid_functions.h" -unsigned int syshid_handle __attribute__((section(".data"))) = 0; +u32 syshid_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(int, HIDSetup,void); EXPORT_DECL(int, HIDTeardown,void); diff --git a/syshid_functions.h b/syshid_functions.h index 08213b4..2fb3140 100644 --- a/syshid_functions.h +++ b/syshid_functions.h @@ -28,7 +28,7 @@ extern "C" { #endif -extern unsigned int syshid_handle; +extern u32 syshid_handle; typedef struct { diff --git a/vpad_functions.c b/vpad_functions.c index 201cf34..ad22eda 100644 --- a/vpad_functions.c +++ b/vpad_functions.c @@ -24,8 +24,8 @@ #include "os_functions.h" #include "vpad_functions.h" -unsigned int vpad_handle __attribute__((section(".data"))) = 0; -unsigned int vpadbase_handle __attribute__((section(".data"))) = 0; +u32 vpad_handle __attribute__((section(".data"))) = 0; +u32 vpadbase_handle __attribute__((section(".data"))) = 0; EXPORT_DECL(void, VPADInit, void); EXPORT_DECL(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error); diff --git a/vpad_functions.h b/vpad_functions.h index 4fafda2..4bdda27 100644 --- a/vpad_functions.h +++ b/vpad_functions.h @@ -28,8 +28,8 @@ extern "C" { #endif -extern unsigned int vpad_handle; -extern unsigned int vpadbase_handle; +extern u32 vpad_handle; +extern u32 vpadbase_handle; #include