diff --git a/libctru/include/3ds.h b/libctru/include/3ds.h index be7a547..58fda13 100644 --- a/libctru/include/3ds.h +++ b/libctru/include/3ds.h @@ -60,6 +60,8 @@ extern "C" { #include <3ds/services/ps.h> #include <3ds/services/ptmu.h> #include <3ds/services/ptmsysm.h> +#include <3ds/services/ptmgets.h> +#include <3ds/services/ptmsets.h> #include <3ds/services/pxidev.h> #include <3ds/services/pxipm.h> #include <3ds/services/soc.h> diff --git a/libctru/include/3ds/services/ptmgets.h b/libctru/include/3ds/services/ptmgets.h new file mode 100644 index 0000000..4464dc8 --- /dev/null +++ b/libctru/include/3ds/services/ptmgets.h @@ -0,0 +1,25 @@ +/** + * @file ptmgets.h + * @brief PTMGETS service. + */ +#pragma once + +#include <3ds/types.h> + +/// Initializes PTMGETS. +Result ptmGetsInit(void); + +/// Exits PTMGETS. +void ptmGetsExit(void); + +/** + * @brief Gets a pointer to the current ptm:gets session handle. + * @return A pointer to the current ptm:gets session handle. + */ +Handle *ptmGetsGetSessionHandle(void); + +/** + * @brief Gets the system time. + * @param[out] outMsY2k The pointer to write the number of milliseconds since 01/01/2000 to. + */ +Result PTMGETS_GetSystemTime(s64 *outMsY2k); diff --git a/libctru/include/3ds/services/ptmsets.h b/libctru/include/3ds/services/ptmsets.h new file mode 100644 index 0000000..f92b58c --- /dev/null +++ b/libctru/include/3ds/services/ptmsets.h @@ -0,0 +1,25 @@ +/** + * @file ptmsets.h + * @brief PTMSETS service. + */ +#pragma once + +#include <3ds/types.h> + +/// Initializes PTMSETS. +Result ptmSetsInit(void); + +/// Exits PTMSETS. +void ptmSetsExit(void); + +/** + * @brief Gets a pointer to the current ptm:sets session handle. + * @return A pointer to the current ptm:sets session handle. + */ +Handle *ptmSetsGetSessionHandle(void); + +/** + * @brief Sets the system time. + * @param msY2k The number of milliseconds since 01/01/2000. + */ +Result PTMSETS_SetSystemTime(s64 msY2k); diff --git a/libctru/include/3ds/services/ptmsysm.h b/libctru/include/3ds/services/ptmsysm.h index a1b7053..253ca3d 100644 --- a/libctru/include/3ds/services/ptmsysm.h +++ b/libctru/include/3ds/services/ptmsysm.h @@ -48,6 +48,12 @@ Result ptmSysmInit(void); /// Exits ptm:sysm. void ptmSysmExit(void); +/** + * @brief Gets a pointer to the current ptm:sysm session handle. + * @return A pointer to the current ptm:sysm session handle. + */ +Handle *ptmSysmGetSessionHandle(void); + /// Requests to enter sleep mode. Result PTMSYSM_RequestSleep(void); @@ -81,12 +87,18 @@ Result PTMSYSM_GetWakeReason(PtmSleepConfig *outSleepConfig); /// Cancels the "half-awake" state and fully wakes up the 3DS after some delay. Result PTMSYSM_Awaken(void); +/** + * @brief Sets the user time by updating the user time offset. + * @param msY2k The number of milliseconds since 01/01/2000. + */ +Result PTMSYSM_SetUserTime(s64 msY2k); + /// Invalidates the "system time" (cfg block 0x30002) Result PTMSYSM_InvalidateSystemTime(void); /** * @brief Reads the time and date coming from the RTC and converts the result. - * @returns The number of milliseconds since 01/01/2000. + * @param[out] outMsY2k The pointer to write the number of milliseconds since 01/01/2000 to. */ Result PTMSYSM_GetRtcTime(s64 *outMsY2k); diff --git a/libctru/include/3ds/services/ptmu.h b/libctru/include/3ds/services/ptmu.h index 1ba4e97..cb987e5 100644 --- a/libctru/include/3ds/services/ptmu.h +++ b/libctru/include/3ds/services/ptmu.h @@ -10,6 +10,12 @@ Result ptmuInit(void); /// Exits PTMU. void ptmuExit(void); +/** + * @brief Gets a pointer to the current ptm:u session handle. + * @return A pointer to the current ptm:u session handle. + */ +Handle *ptmuGetSessionHandle(void); + /** * @brief Gets the system's current shell state. * @param out Pointer to write the current shell state to. (0 = closed, 1 = open) diff --git a/libctru/source/services/ptmgets.c b/libctru/source/services/ptmgets.c new file mode 100644 index 0000000..f4e6c35 --- /dev/null +++ b/libctru/source/services/ptmgets.c @@ -0,0 +1,43 @@ +#include +#include <3ds/types.h> +#include <3ds/result.h> +#include <3ds/svc.h> +#include <3ds/srv.h> +#include <3ds/synchronization.h> +#include <3ds/services/ptmgets.h> +#include <3ds/ipc.h> + +static Handle ptmGetsHandle; +static int ptmGetsRefCount; + +Result ptmGetsInit(void) +{ + if (AtomicPostIncrement(&ptmGetsRefCount)) return 0; + Result res = srvGetServiceHandle(&ptmGetsHandle, "ptm:gets"); + if (R_FAILED(res)) AtomicDecrement(&ptmGetsRefCount); + return res; +} + +void ptmGetsExit(void) +{ + if (AtomicDecrement(&ptmGetsRefCount)) return; + svcCloseHandle(ptmGetsHandle); +} + +Handle *ptmGetsGetSessionHandle(void) +{ + return &ptmGetsHandle; +} + +Result PTMGETS_GetSystemTime(s64 *outMsY2k) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x401,0,0); // 0x04010000 + + if(R_FAILED(ret = svcSendSyncRequest(ptmGetsHandle)))return ret; + + memcpy(outMsY2k, &cmdbuf[2], 8); + + return (Result)cmdbuf[1]; +} diff --git a/libctru/source/services/ptmsets.c b/libctru/source/services/ptmsets.c new file mode 100644 index 0000000..740bc4e --- /dev/null +++ b/libctru/source/services/ptmsets.c @@ -0,0 +1,42 @@ +#include +#include <3ds/types.h> +#include <3ds/result.h> +#include <3ds/svc.h> +#include <3ds/srv.h> +#include <3ds/synchronization.h> +#include <3ds/services/ptmsets.h> +#include <3ds/ipc.h> + +static Handle ptmSetsHandle; +static int ptmSetsRefCount; + +Result ptmSetsInit(void) +{ + if (AtomicPostIncrement(&ptmSetsRefCount)) return 0; + Result res = srvGetServiceHandle(&ptmSetsHandle, "ptm:sets"); + if (R_FAILED(res)) AtomicDecrement(&ptmSetsRefCount); + return res; +} + +void ptmSetsExit(void) +{ + if (AtomicDecrement(&ptmSetsRefCount)) return; + svcCloseHandle(ptmSetsHandle); +} + +Handle *ptmSetsGetSessionHandle(void) +{ + return &ptmSetsHandle; +} + +Result PTMSETS_SetSystemTime(s64 msY2k) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x1,2,0); // 0x00010080 + memcpy(&cmdbuf[1], &msY2k, 8); + + if(R_FAILED(ret = svcSendSyncRequest(ptmSetsHandle)))return ret; + + return (Result)cmdbuf[1]; +} diff --git a/libctru/source/services/ptmsysm.c b/libctru/source/services/ptmsysm.c index b9b1b85..f376f0d 100644 --- a/libctru/source/services/ptmsysm.c +++ b/libctru/source/services/ptmsysm.c @@ -24,6 +24,11 @@ void ptmSysmExit(void) svcCloseHandle(ptmSysmHandle); } +Handle *ptmSysmGetSessionHandle(void) +{ + return &ptmSysmHandle; +} + Result PTMSYSM_RequestSleep(void) { Result ret; @@ -144,6 +149,18 @@ Result PTMSYSM_RebootAsync(u64 timeout) return (Result)cmdbuf[1]; } +Result PTMSYSM_SetUserTime(s64 msY2k) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x80C,2,0); // 0x080C0080 + memcpy(&cmdbuf[1], &msY2k, 8); + + if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret; + + return (Result)cmdbuf[1]; +} + Result PTMSYSM_InvalidateSystemTime(void) { Result ret; diff --git a/libctru/source/services/ptmu.c b/libctru/source/services/ptmu.c index 8db305d..84b606b 100644 --- a/libctru/source/services/ptmu.c +++ b/libctru/source/services/ptmu.c @@ -24,6 +24,11 @@ void ptmuExit(void) svcCloseHandle(ptmuHandle); } +Handle *ptmuGetSessionHandle(void) +{ + return &ptmuHandle; +} + Result PTMU_GetShellState(u8 *out) { Result ret=0;