2021-02-10 16:28:47 +00:00
|
|
|
#include "current_cfw.hpp"
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
bool isServiceRunning(const char *serviceName) {
|
|
|
|
Handle handle;
|
|
|
|
SmServiceName service_name = smEncodeName(serviceName);
|
|
|
|
bool running = R_FAILED(smRegisterService(&handle, service_name, false, 1));
|
|
|
|
svcCloseHandle(handle);
|
|
|
|
if (!running)
|
|
|
|
smUnregisterService(service_name);
|
|
|
|
|
|
|
|
return running;
|
2021-02-26 18:21:49 +00:00
|
|
|
}
|
2021-02-10 16:28:47 +00:00
|
|
|
|
2021-02-24 19:44:15 +00:00
|
|
|
Result smAtmosphereHasService(bool *out, SmServiceName name) {
|
|
|
|
u8 tmp = 0;
|
|
|
|
Result rc = serviceDispatchInOut(smGetServiceSession(), 65100, name, tmp);
|
|
|
|
if (R_SUCCEEDED(rc) && out)
|
|
|
|
*out = tmp;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-02-10 16:28:47 +00:00
|
|
|
CFW getCFW(){
|
2021-02-24 19:44:15 +00:00
|
|
|
bool res = false;
|
2021-02-25 21:05:47 +00:00
|
|
|
if(R_SUCCEEDED(smAtmosphereHasService(&res, smEncodeName("rnx")))) {
|
|
|
|
if(res)
|
|
|
|
return rnx;
|
|
|
|
smAtmosphereHasService(&res, smEncodeName("tx"));
|
|
|
|
if(res)
|
|
|
|
return sxos;
|
|
|
|
}
|
|
|
|
else { // use old method just in case
|
2021-02-26 18:21:49 +00:00
|
|
|
if(isServiceRunning("rnx")) return rnx;
|
|
|
|
if(isServiceRunning("tx")) return sxos;
|
2021-02-25 21:05:47 +00:00
|
|
|
}
|
2021-02-24 19:44:15 +00:00
|
|
|
return ams;
|
2021-02-26 18:21:49 +00:00
|
|
|
}
|