Added APT CheckNew3DS code. Added code for attempting to use the other APT services when APT:U isn't accessible.

This commit is contained in:
yellows8 2014-11-01 21:39:18 -04:00
parent c38276e37d
commit c8795b1b79
2 changed files with 72 additions and 2 deletions

View File

@ -69,3 +69,7 @@ Result APT_PrepareToCloseApplication(Handle* handle, u8 a);
Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c);
Result APT_SetAppCpuTimeLimit(Handle* handle, u32 percent);
Result APT_GetAppCpuTimeLimit(Handle* handle, u32 *percent);
Result APT_CheckNew3DS_Application(Handle* handle, u8 *out);//*Application and *System use APT commands 0x01010000 and 0x01020000. Using APT_CheckNew3DS() is recommended, this determines which of those two funcs to use automatically.
Result APT_CheckNew3DS_System(Handle* handle, u8 *out);
Result APT_CheckNew3DS(Handle* handle, u8 *out);

View File

@ -14,6 +14,9 @@ extern u32 __system_runflags;
NS_APPID currentAppId;
static char *__apt_servicestr = NULL;
static char *__apt_servicenames[3] = {"APT:U", "APT:S", "APT:A"};
Handle aptLockHandle;
Handle aptuHandle;
Handle aptEvents[3];
@ -32,6 +35,29 @@ u32 aptParameters[0x1000/4]; //TEMP
static void aptAppStarted(void);
static Result __apt_initservicehandle()
{
Result ret=0;
u32 i;
if(__apt_servicestr)
{
return srvGetServiceHandle(&aptuHandle, __apt_servicestr);
}
for(i=0; i<3; i++)
{
ret = srvGetServiceHandle(&aptuHandle, __apt_servicenames[i]);
if(ret==0)
{
__apt_servicestr = __apt_servicenames[i];
return ret;
}
}
return ret;
}
void aptInitCaptureInfo(u32 *ns_capinfo)
{
u32 tmp=0;
@ -303,7 +329,8 @@ Result aptInit(void)
Result ret=0;
// Initialize APT stuff, escape load screen.
srvGetServiceHandle(&aptuHandle, "APT:U");
ret = __apt_initservicehandle();
if(ret!=0)return ret;
if((ret=APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle)))return ret;
svcCloseHandle(aptuHandle);
@ -439,8 +466,10 @@ void aptSetStatusPower(u32 status)
void aptOpenSession()
{
//Result ret;
svcWaitSynchronization(aptLockHandle, U64_MAX);
srvGetServiceHandle(&aptuHandle, "APT:U");
__apt_initservicehandle();
}
void aptCloseSession()
@ -768,3 +797,40 @@ Result APT_GetAppCpuTimeLimit(Handle* handle, u32 *percent)
return cmdbuf[1];
}
Result APT_CheckNew3DS_Application(Handle* handle, u8 *out)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x01010000;
Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret;
if(out)*out=cmdbuf[2];
return cmdbuf[1];
}
Result APT_CheckNew3DS_System(Handle* handle, u8 *out)
{
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x01020000;
Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret;
if(out)*out=cmdbuf[2];
return cmdbuf[1];
}
Result APT_CheckNew3DS(Handle* handle, u8 *out)
{
if(currentAppId==APPID_APPLICATION)return APT_CheckNew3DS_Application(NULL, out);
return APT_CheckNew3DS_System(NULL, out);
}