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
26 changes: 26 additions & 0 deletions nx/include/switch/services/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2624,3 +2624,29 @@ Result setcalGetDeviceId(u64 *out_device_id);
* @param[out] out_type Output ConsoleSixAxisSensorMountType.
*/
Result setcalGetConsoleSixAxisSensorMountType(u8 *out_type);

/// Initialize setfd.
/// [4.0.0+] Only exposed if in development mode.
Result setfdInitialize(void);

/// Exit setfd.
void setfdExit(void);

/// Gets the Service object for the actual setfd service session.
Service* setfdGetServiceSession(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);
59 changes: 59 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 @@ -59,6 +60,20 @@ Service* setcalGetServiceSession(void) {
return &g_setcalSrv;
}

NX_GENERATE_SERVICE_GUARD(setfd);

Result _setfdInitialize(void) {
return smGetService(&g_setfdSrv, "set:fd");
}

void _setfdCleanup(void) {
serviceClose(&g_setfdSrv);
}

Service* setfdGetServiceSession(void) {
return &g_setfdSrv;
}

static Result _setCmdGetHandle(Service* srv, Handle* handle_out, u32 cmd_id) {
return serviceDispatch(srv, cmd_id,
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
Expand Down Expand Up @@ -1823,3 +1838,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 },
}
);
}