diff --git a/nx/include/switch/applets/hid_la.h b/nx/include/switch/applets/hid_la.h index 7006e37b..4e0a9824 100644 --- a/nx/include/switch/applets/hid_la.h +++ b/nx/include/switch/applets/hid_la.h @@ -10,9 +10,10 @@ /// Mode values for HidLaControllerSupportArgPrivate::mode. typedef enum { - HidLaControllerSupportMode_ShowControllerSupport = 0, ///< ShowControllerSupport - HidLaControllerSupportMode_ShowControllerStrapGuide = 1, ///< [3.0.0+] ShowControllerStrapGuide - HidLaControllerSupportMode_ShowControllerFirmwareUpdate = 2, ///< [3.0.0+] ShowControllerFirmwareUpdate + HidLaControllerSupportMode_ShowControllerSupport = 0, ///< ShowControllerSupport + HidLaControllerSupportMode_ShowControllerStrapGuide = 1, ///< [3.0.0+] ShowControllerStrapGuide + HidLaControllerSupportMode_ShowControllerFirmwareUpdate = 2, ///< [3.0.0+] ShowControllerFirmwareUpdate + HidLaControllerSupportMode_ShowControllerKeyRemappingForSystem = 4, ///< [11.0.0+] ShowControllerKeyRemappingForSystem } HidLaControllerSupportMode; /// ControllerSupportCaller @@ -75,6 +76,13 @@ typedef struct { u8 pad[3]; ///< Padding. } HidLaControllerFirmwareUpdateArg; +/// ControllerKeyRemappingArg +typedef struct { + u64 unk_x0; ///< Unknown + u32 unk_x8; ///< Unknown + u8 pad[0x4]; ///< Padding +} HidLaControllerKeyRemappingArg; + /// ControllerSupportResultInfo. First 8-bytes from the applet output storage. typedef struct { s8 player_count; ///< playerCount. @@ -103,6 +111,13 @@ void hidLaCreateControllerSupportArg(HidLaControllerSupportArg *arg); */ void hidLaCreateControllerFirmwareUpdateArg(HidLaControllerFirmwareUpdateArg *arg); +/** + * @brief Initializes a \ref HidLaControllerKeyRemappingArg with the defaults. + * @note This just uses memset() with the arg. + * @param[out] arg \ref HidLaControllerKeyRemappingArg + */ +void hidLaCreateControllerKeyRemappingArg(HidLaControllerKeyRemappingArg *arg); + /** * @brief Sets the ExplainText for the specified player and \ref HidLaControllerSupportArg. * @note This string is displayed in the UI box for the player. @@ -150,3 +165,11 @@ Result hidLaShowControllerSupportForSystem(HidLaControllerSupportResultInfo *res */ Result hidLaShowControllerFirmwareUpdateForSystem(const HidLaControllerFirmwareUpdateArg *arg, HidLaControllerSupportCaller caller); +/** + * @brief Launches the applet for ControllerKeyRemappingForSystem. + * @note Only available on [11.0.0+]. + * @param[in] arg \ref HidLaControllerKeyRemappingArg + * @param[in] caller \ref HidLaControllerSupportCaller + */ +Result hidLaShowControllerKeyRemappingForSystem(const HidLaControllerKeyRemappingArg *arg, HidLaControllerSupportCaller caller); + diff --git a/nx/source/applets/hid_la.c b/nx/source/applets/hid_la.c index 14e6e9bd..4711c14f 100644 --- a/nx/source/applets/hid_la.c +++ b/nx/source/applets/hid_la.c @@ -9,7 +9,9 @@ static Result _hidLaShow(const HidLaControllerSupportArgPrivate *private_arg, co AppletHolder holder; u32 version=0x3; // [1.0.0+] - if (hosversionAtLeast(8,0,0)) + if (hosversionAtLeast(11,0,0)) + version = 0x8; + else if (hosversionAtLeast(8,0,0)) version = 0x7; else if (hosversionAtLeast(6,0,0)) version = 0x5; @@ -32,12 +34,19 @@ static Result _hidLaShow(const HidLaControllerSupportArgPrivate *private_arg, co return rc; } +static size_t _hidLaGetControllerSupportArgSize(void) { + size_t arg_size = sizeof(HidLaControllerSupportArg); + if (hosversionBefore(8,0,0)) arg_size = sizeof(HidLaControllerSupportArgV3); + + return arg_size; +} + static Result _hidLaShowControllerSupportCore(HidLaControllerSupportResultInfo *result_info, const HidLaControllerSupportArg *arg, const HidLaControllerSupportArgPrivate *private_arg) { Result rc=0; HidLaControllerSupportResultInfoInternal res={0}; HidLaControllerSupportArgV3 arg_v3; const void* arg_ptr = arg; - size_t arg_size = sizeof(*arg); + size_t arg_size = _hidLaGetControllerSupportArgSize(); if (private_arg->mode == HidLaControllerSupportMode_ShowControllerFirmwareUpdate) return MAKERESULT(Module_Libnx, LibnxError_BadInput); @@ -45,7 +54,6 @@ static Result _hidLaShowControllerSupportCore(HidLaControllerSupportResultInfo * if (hosversionBefore(8,0,0)) { memset(&arg_v3, 0, sizeof(arg_v3)); arg_ptr = &arg_v3; - arg_size = sizeof(arg_v3); memcpy(&arg_v3.hdr, &arg->hdr, sizeof(arg->hdr)); memcpy(arg_v3.identification_color, arg->identification_color, sizeof(arg_v3.identification_color)); @@ -90,6 +98,25 @@ static Result _hidLaShowControllerFirmwareUpdateCore(const HidLaControllerFirmwa return rc; } +static Result _hidLaShowControllerKeyRemappingCore(const HidLaControllerKeyRemappingArg *arg, const HidLaControllerSupportArgPrivate *private_arg) { + Result rc=0; + HidLaControllerSupportResultInfoInternal res={0}; + + if (hosversionBefore(11,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (private_arg->mode != HidLaControllerSupportMode_ShowControllerKeyRemappingForSystem) + return MAKERESULT(Module_Libnx, LibnxError_BadInput); + + rc = _hidLaShow(private_arg, arg, sizeof(*arg), &res, sizeof(res)); + if (R_SUCCEEDED(rc)) { + if (res.res != 0) { + rc = MAKERESULT(Module_Libnx, LibnxError_LibAppletBadExit); + } + } + + return rc; +} + static Result _hidLaSetupControllerSupportArgPrivate(HidLaControllerSupportArgPrivate *private_arg) { Result rc=0; u32 style_set; @@ -119,6 +146,10 @@ void hidLaCreateControllerFirmwareUpdateArg(HidLaControllerFirmwareUpdateArg *ar memset(arg, 0, sizeof(*arg)); } +void hidLaCreateControllerKeyRemappingArg(HidLaControllerKeyRemappingArg *arg) { + memset(arg, 0, sizeof(*arg)); +} + Result hidLaSetExplainText(HidLaControllerSupportArg *arg, const char *str, HidNpadIdType id) { if (id >= 8) return MAKERESULT(Module_Libnx, LibnxError_BadInput); @@ -132,7 +163,7 @@ Result hidLaSetExplainText(HidLaControllerSupportArg *arg, const char *str, HidN Result hidLaShowControllerSupport(HidLaControllerSupportResultInfo *result_info, const HidLaControllerSupportArg *arg) { Result rc=0; HidLaControllerSupportArgPrivate private_arg = { - .private_size = sizeof(private_arg), .arg_size = sizeof(*arg), .mode = HidLaControllerSupportMode_ShowControllerSupport + .private_size = sizeof(private_arg), .arg_size = _hidLaGetControllerSupportArgSize(), .mode = HidLaControllerSupportMode_ShowControllerSupport }; rc = _hidLaSetupControllerSupportArgPrivate(&private_arg); @@ -146,7 +177,7 @@ Result hidLaShowControllerStrapGuide(void) { Result rc=0; HidLaControllerSupportArg arg; HidLaControllerSupportArgPrivate private_arg = { - .private_size = sizeof(private_arg), .arg_size = sizeof(arg), .mode = HidLaControllerSupportMode_ShowControllerStrapGuide + .private_size = sizeof(private_arg), .arg_size = _hidLaGetControllerSupportArgSize(), .mode = HidLaControllerSupportMode_ShowControllerStrapGuide }; if (hosversionBefore(3,0,0)) return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); @@ -163,7 +194,7 @@ Result hidLaShowControllerStrapGuide(void) { Result hidLaShowControllerFirmwareUpdate(const HidLaControllerFirmwareUpdateArg *arg) { Result rc=0; HidLaControllerSupportArgPrivate private_arg = { - .private_size = sizeof(private_arg), .arg_size = sizeof(*arg), .mode = HidLaControllerSupportMode_ShowControllerFirmwareUpdate + .private_size = sizeof(private_arg), .arg_size = _hidLaGetControllerSupportArgSize(), .mode = HidLaControllerSupportMode_ShowControllerFirmwareUpdate }; rc = _hidLaSetupControllerSupportArgPrivate(&private_arg); @@ -176,7 +207,7 @@ Result hidLaShowControllerFirmwareUpdate(const HidLaControllerFirmwareUpdateArg Result hidLaShowControllerSupportForSystem(HidLaControllerSupportResultInfo *result_info, const HidLaControllerSupportArg *arg, bool flag) { Result rc=0; HidLaControllerSupportArgPrivate private_arg = { - .private_size = sizeof(private_arg), .arg_size = sizeof(*arg), + .private_size = sizeof(private_arg), .arg_size = _hidLaGetControllerSupportArgSize(), .flag0 = flag!=0, .flag1 = 1, .mode = HidLaControllerSupportMode_ShowControllerSupport }; @@ -196,7 +227,7 @@ Result hidLaShowControllerSupportForSystem(HidLaControllerSupportResultInfo *res Result hidLaShowControllerFirmwareUpdateForSystem(const HidLaControllerFirmwareUpdateArg *arg, HidLaControllerSupportCaller caller) { Result rc=0; HidLaControllerSupportArgPrivate private_arg = { - .private_size = sizeof(private_arg), .arg_size = sizeof(*arg), + .private_size = sizeof(private_arg), .arg_size = _hidLaGetControllerSupportArgSize(), .flag1 = 1, .mode = HidLaControllerSupportMode_ShowControllerFirmwareUpdate, .controller_support_caller = caller }; @@ -207,3 +238,17 @@ Result hidLaShowControllerFirmwareUpdateForSystem(const HidLaControllerFirmwareU return rc; } +Result hidLaShowControllerKeyRemappingForSystem(const HidLaControllerKeyRemappingArg *arg, HidLaControllerSupportCaller caller) { + Result rc=0; + HidLaControllerSupportArgPrivate private_arg = { + .private_size = sizeof(private_arg), .arg_size = _hidLaGetControllerSupportArgSize(), + .flag1 = 1, .mode = HidLaControllerSupportMode_ShowControllerKeyRemappingForSystem, .controller_support_caller = caller + }; + + rc = _hidLaSetupControllerSupportArgPrivate(&private_arg); + + if (R_SUCCEEDED(rc)) rc = _hidLaShowControllerKeyRemappingCore(arg, &private_arg); + + return rc; +} +