Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions nx/include/switch/services/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2624,3 +2624,25 @@ Result setcalGetDeviceId(u64 *out_device_id);
* @param[out] out_type Output ConsoleSixAxisSensorMountType.
*/
Result setcalGetConsoleSixAxisSensorMountType(u8 *out_type);

// Initialize setfd.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment: [4.0.0+] Only exposed if in development mode.

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);
55 changes: 55 additions & 0 deletions nx/source/services/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 },
}
);
}