Skip to content

Commit

Permalink
Keeping the patient alive (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
HookedBehemoth authored Jun 8, 2020
1 parent 870bbbe commit dc14c3a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 71 deletions.
5 changes: 0 additions & 5 deletions include/helpers/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
extern "C" {
#endif

Result amspmdmntInitialize(void);
void amspmdmntExit(void);

Result amspmdmntAtmosphereGetProcessHandle(Handle *out_processHandle);

bool isServiceRunning(const char *serviceName);
void getCurrTimeString(char *buffer);
void getCurrBatteryPercentage(char *buffer);
Expand Down
6 changes: 3 additions & 3 deletions source/guis/gui_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@ void uploadBackup(std::string path, std::string fileName) {
(new MessageBox("Uploading savefile...\n \nPress \uE0E1 to cancel.", MessageBox::NONE))->show();
requestDraw();

char serial[0x19];
SetSysSerialNumber serial;
u8 serialHash[0x20];
setsysGetSerialNumber(serial);
setsysGetSerialNumber(&serial);


Sha256Context shaCtx;
sha256ContextCreate(&shaCtx);
sha256ContextUpdate(&shaCtx, (u8 *)serial, 0x19);
sha256ContextUpdate(&shaCtx, (u8 *)serial.number, 0x19);
sha256ContextGetHash(&shaCtx, serialHash);

hashStr.str("");
Expand Down
68 changes: 6 additions & 62 deletions source/helpers/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,18 @@

#define MHz *1E6

static Service g_pmdmntService;
static u64 g_refCnt;

static u64 g_uniquePadIds[2];
static size_t g_uniquePadCnt;
static HidsysNotificationLedPattern g_patternOn, g_patternOff;

Result amspmdmntInitialize(void) {
atomicIncrement64(&g_refCnt);

if (serviceIsActive(&g_pmdmntService))
return 1;

return smGetService(&g_pmdmntService, "pm:dmnt");
}

void amspmdmntExit(void) {
if (atomicDecrement64(&g_refCnt) == 0) {
serviceClose(&g_pmdmntService);
}
}

bool isServiceRunning(const char *serviceName) {
Handle handle;
u8 tmp=0;
SmServiceName service_name = smEncodeName(serviceName);
bool running = R_FAILED(smRegisterService(&handle, service_name, false, 1));

svcCloseHandle(handle);

if (!running)
smUnregisterService(service_name);

return running;
Result rc = serviceDispatchInOut(smGetServiceSession(), 65100, service_name, tmp);
if (R_SUCCEEDED(rc) && tmp & 1)
return true;
else
return false;
}

void getCurrTimeString(char *buffer) {
Expand Down Expand Up @@ -86,38 +65,3 @@ void overclockSystem(bool enable) {
clkrstCloseSession(&clkrstSession);
}
}

Result amspmdmntAtmosphereGetProcessHandle(Handle *out_processHandle) {
IpcCommand c;
ipcInitialize(&c);

struct {
u64 magic;
u64 cmd_id;
} *raw;

raw = ipcPrepareHeader(&c, sizeof(*raw));

raw->magic = SFCI_MAGIC;
raw->cmd_id = 65000;

Result rc = serviceIpcDispatch(&g_pmdmntService);

if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;

struct {
u64 magic;
u64 result;
} *resp;

serviceIpcParse(&g_pmdmntService, &r, sizeof(*resp));
resp = r.Raw;

*out_processHandle = r.Handles[0];

rc = resp->result;
}

return rc;
}
2 changes: 1 addition & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void serviceInitialize() {
socketInitializeDefault();
nsInitialize();
accountInitialize(AccountServiceType_Administrator);
plInitialize();
plInitialize(PlServiceType_User);
psmInitialize();
pminfoInitialize();
pmdmntInitialize();
Expand Down

0 comments on commit dc14c3a

Please sign in to comment.