Fixed appletQueryApplicationPlayStatistics and added appletQueryApplicationPlayStatisticsByUid. Renamed AppletApplicationPlayStatistics to PdmApplicationPlayStatistics, updated it, and moved it to new file pdm.h.

This commit is contained in:
yellows8 2019-06-29 20:44:03 -04:00
parent 8147dca2a4
commit 7f7ba17802
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
4 changed files with 84 additions and 14 deletions

View File

@ -90,6 +90,7 @@ extern "C" {
#include "switch/services/nfc.h" #include "switch/services/nfc.h"
#include "switch/services/wlaninf.h" #include "switch/services/wlaninf.h"
#include "switch/services/pctl.h" #include "switch/services/pctl.h"
#include "switch/services/pdm.h"
#include "switch/display/binder.h" #include "switch/display/binder.h"
#include "switch/display/parcel.h" #include "switch/display/parcel.h"

View File

@ -9,6 +9,7 @@
#include "../types.h" #include "../types.h"
#include "../services/sm.h" #include "../services/sm.h"
#include "../services/apm.h" #include "../services/apm.h"
#include "../services/pdm.h"
#include "../kernel/tmem.h" #include "../kernel/tmem.h"
#include "../kernel/event.h" #include "../kernel/event.h"
@ -135,11 +136,6 @@ typedef struct {
LibAppletExitReason exitreason; ///< Set by \ref appletHolderJoin using the output from cmd GetResult, see \ref LibAppletExitReason. LibAppletExitReason exitreason; ///< Set by \ref appletHolderJoin using the output from cmd GetResult, see \ref LibAppletExitReason.
} AppletHolder; } AppletHolder;
/// 'pdm' ApplicationPlayStatistics
typedef struct {
u8 unk_x0[0x8];
} AppletApplicationPlayStatistics;
/// Attributes for launching applications for Quest. /// Attributes for launching applications for Quest.
typedef struct { typedef struct {
u32 unk_x0; u32 unk_x0;
@ -226,13 +222,24 @@ Result appletEndBlockingHomeButton(void);
/** /**
* @brief Gets ApplicationPlayStatistics. * @brief Gets ApplicationPlayStatistics.
* @note Only available with AppletType_*Application on 5.0.0+. * @note Only available with AppletType_*Application on 5.0.0+.
* @note This may return no output in some cases. * @note The input titleIDs must be allowed via control.nacp with the current host title. The minimum allowed titleID is the titleID for the current-process.
* @param stats Output \ref AppletApplicationPlayStatistics array. * @param stats Output \ref PdmApplicationPlayStatistics array.
* @param titleIDs Input titleIDs array. * @param titleIDs Input titleIDs array.
* @param count Total entries in the input/output arrays. * @param count Total entries in the input/output arrays.
* @param out Output s32. * @param total_out Total output entries.
*/ */
Result appletQueryApplicationPlayStatistics(AppletApplicationPlayStatistics *stats, const u64 *titleIDs, s32 count, s32 *out); Result appletQueryApplicationPlayStatistics(PdmApplicationPlayStatistics *stats, const u64 *titleIDs, s32 count, s32 *total_out);
/**
* @brief Same as \ref appletQueryApplicationPlayStatistics except this gets playstats specific to the input userID.
* @note Only available with AppletType_*Application on 6.0.0+.
* @param userID userID
* @param stats Output \ref PdmApplicationPlayStatistics array.
* @param titleIDs Input titleIDs array.
* @param count Total entries in the input/output arrays.
* @param total_out Total output entries.
*/
Result appletQueryApplicationPlayStatisticsByUid(u128 userID, PdmApplicationPlayStatistics *stats, const u64 *titleIDs, s32 count, s32 *total_out);
/** /**
* @brief Delay exiting until \ref appletUnlockExit is called, with a 15 second timeout once exit is requested. * @brief Delay exiting until \ref appletUnlockExit is called, with a 15 second timeout once exit is requested.

View File

@ -0,0 +1,16 @@
/**
* @file pdm.h
* @brief PDM (pdm:*) service IPC wrapper.
* @author yellows8
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#include "../services/sm.h"
/// ApplicationPlayStatistics
typedef struct {
u64 titleID; ///< titleID
u8 unk_x8[0x10]; ///< Unknown
} PdmApplicationPlayStatistics;

View File

@ -1445,8 +1445,8 @@ Result appletInitializeGamePlayRecording(void) {
return rc; return rc;
} }
//Official sw has this under 'pdm'. //Official sw has these under 'pdm'.
Result appletQueryApplicationPlayStatistics(AppletApplicationPlayStatistics *stats, const u64 *titleIDs, s32 count, s32 *out) { Result appletQueryApplicationPlayStatistics(PdmApplicationPlayStatistics *stats, const u64 *titleIDs, s32 count, s32 *total_out) {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);
@ -1456,8 +1456,8 @@ Result appletQueryApplicationPlayStatistics(AppletApplicationPlayStatistics *sta
if (hosversionBefore(5,0,0)) if (hosversionBefore(5,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
ipcAddRecvBuffer(&c, stats, count*sizeof(AppletApplicationPlayStatistics), BufferType_Normal);
ipcAddSendBuffer(&c, titleIDs, count*sizeof(u64), BufferType_Normal); ipcAddSendBuffer(&c, titleIDs, count*sizeof(u64), BufferType_Normal);
ipcAddRecvBuffer(&c, stats, count*sizeof(PdmApplicationPlayStatistics), BufferType_Normal);
struct { struct {
u64 magic; u64 magic;
@ -1476,7 +1476,7 @@ Result appletQueryApplicationPlayStatistics(AppletApplicationPlayStatistics *sta
struct { struct {
u64 magic; u64 magic;
u64 result; u64 result;
s32 out; s32 total_out;
} *resp; } *resp;
serviceIpcParse(&g_appletIFunctions, &r, sizeof(*resp)); serviceIpcParse(&g_appletIFunctions, &r, sizeof(*resp));
@ -1484,7 +1484,53 @@ Result appletQueryApplicationPlayStatistics(AppletApplicationPlayStatistics *sta
rc = resp->result; rc = resp->result;
if (R_SUCCEEDED(rc) && out) *out = resp->out; if (R_SUCCEEDED(rc) && total_out) *total_out = resp->total_out;
}
return rc;
}
Result appletQueryApplicationPlayStatisticsByUid(u128 userID, PdmApplicationPlayStatistics *stats, const u64 *titleIDs, s32 count, s32 *total_out) {
IpcCommand c;
ipcInitialize(&c);
if (!serviceIsActive(&g_appletSrv) || !_appletIsRegularApplication())
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
if (hosversionBefore(6,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
ipcAddSendBuffer(&c, titleIDs, count*sizeof(u64), BufferType_Normal);
ipcAddRecvBuffer(&c, stats, count*sizeof(PdmApplicationPlayStatistics), BufferType_Normal);
struct {
u64 magic;
u64 cmd_id;
u128 userID;
} *raw;
raw = serviceIpcPrepareHeader(&g_appletIFunctions, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 111;
raw->userID = userID;
Result rc = serviceIpcDispatch(&g_appletIFunctions);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
s32 total_out;
} *resp;
serviceIpcParse(&g_appletIFunctions, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && total_out) *total_out = resp->total_out;
} }
return rc; return rc;