diff --git a/nx/include/switch/services/set.h b/nx/include/switch/services/set.h index 0c7c1dc33..68e28bd05 100644 --- a/nx/include/switch/services/set.h +++ b/nx/include/switch/services/set.h @@ -2624,3 +2624,25 @@ Result setcalGetDeviceId(u64 *out_device_id); * @param[out] out_type Output ConsoleSixAxisSensorMountType. */ Result setcalGetConsoleSixAxisSensorMountType(u8 *out_type); + +// Initialize setfd. +Result setfdInitialize(void); + +// Exit setfd. +void setfdExit(void); + +/** + * @brief Sets the value of a settings item. + * @param name Name string. + * @param item_key Item key string. + * @param value_in Pointer to input value. + * @param value_in_size Size of the value_in buffer. + */ +Result setfdSetSettingsItemValue(const char *name, const char *item_key, const void *value_in, s64 value_in_size); + +/** + * @brief Resets the value of a settings item. + * @param name Name string. + * @param item_key Item key string. + */ +Result setfdResetSettingsItemValue(const char *name, const char *item_key); diff --git a/nx/source/services/set.c b/nx/source/services/set.c index 4b3904943..e92bb9cb2 100644 --- a/nx/source/services/set.c +++ b/nx/source/services/set.c @@ -8,6 +8,7 @@ static Service g_setSrv; static Service g_setsysSrv; static Service g_setcalSrv; +static Service g_setfdSrv; static bool g_setLanguageCodesInitialized; static u64 g_setLanguageCodes[0x40]; @@ -55,6 +56,16 @@ void _setcalCleanup(void) { serviceClose(&g_setcalSrv); } +NX_GENERATE_SERVICE_GUARD(setfd); + +Result _setfdInitialize(void) { + return smGetService(&g_setfdSrv, "set:fd"); +} + +void _setfdCleanup(void) { + serviceClose(&g_setfdSrv); +} + Service* setcalGetServiceSession(void) { return &g_setcalSrv; } @@ -1823,3 +1834,47 @@ Result setcalGetConsoleSixAxisSensorMountType(u8 *out_type) { return _setCmdNoInOutU8(&g_setcalSrv, out_type, 43); } + +Result setfdSetSettingsItemValue(const char *name, const char *item_key, const void *value_in, s64 value_in_size) { + char send_name[SET_MAX_NAME_SIZE]; + char send_item_key[SET_MAX_NAME_SIZE]; + + memset(send_name, 0, SET_MAX_NAME_SIZE); + memset(send_item_key, 0, SET_MAX_NAME_SIZE); + strncpy(send_name, name, SET_MAX_NAME_SIZE-1); + strncpy(send_item_key, item_key, SET_MAX_NAME_SIZE-1); + + return serviceDispatch(&g_setfdSrv, 2, + .buffer_attrs = { + SfBufferAttr_HipcPointer | SfBufferAttr_In, + SfBufferAttr_HipcPointer | SfBufferAttr_In, + SfBufferAttr_HipcMapAlias | SfBufferAttr_In, + }, + .buffers = { + { send_name, SET_MAX_NAME_SIZE }, + { send_item_key, SET_MAX_NAME_SIZE }, + { item_key, value_in_size }, + } + ); +} + +Result setfdResetSettingsItemValue(const char *name, const char *item_key) { + char send_name[SET_MAX_NAME_SIZE]; + char send_item_key[SET_MAX_NAME_SIZE]; + + memset(send_name, 0, SET_MAX_NAME_SIZE); + memset(send_item_key, 0, SET_MAX_NAME_SIZE); + strncpy(send_name, name, SET_MAX_NAME_SIZE-1); + strncpy(send_item_key, item_key, SET_MAX_NAME_SIZE-1); + + return serviceDispatch(&g_setfdSrv, 3, + .buffer_attrs = { + SfBufferAttr_HipcPointer | SfBufferAttr_In, + SfBufferAttr_HipcPointer | SfBufferAttr_In + }, + .buffers = { + { send_name, SET_MAX_NAME_SIZE }, + { send_item_key, SET_MAX_NAME_SIZE }, + } + ); +}