]> Chaos Git - corbenik/ctrulib.git/commitdiff
Added APT CheckNew3DS code. Added code for attempting to use the other APT services...
authoryellows8 <yellows8@users.noreply.github.com>
Sun, 2 Nov 2014 01:39:18 +0000 (21:39 -0400)
committeryellows8 <yellows8@users.noreply.github.com>
Sun, 2 Nov 2014 01:39:18 +0000 (21:39 -0400)
libctru/include/3ds/services/apt.h
libctru/source/services/apt.c

index cf2fb3162cb8c34f8554c1befbc9ecf9dbad7191..3092f99ed667b0bc5593826fb183f083a9d327f9 100644 (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);
+
index 3b995a856274b9d24285caa5f186d308f1e84eb6..d13d15e8060701df3cf525ae936b60231024587b 100644 (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);
+}
+