-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.cpp
94 lines (81 loc) · 2.58 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#define TESLA_INIT_IMPL
#include "tune.h"
#include "gui_error.hpp"
#include "gui_main.hpp"
#include "sdmc/sdmc.hpp"
#include "pm/pm.hpp"
#include "config/config.hpp"
#include <tesla.hpp>
class SysTuneOverlay final : public tsl::Overlay {
private:
const char *msg = nullptr;
Result fail = 0;
public:
void initServices() override {
if (R_FAILED(pm::Initialize())) {
this->msg = "Failed pm::Initialize()";
return;
}
// don't open sys-tune if blacklisted title is active!
u64 pid{}, tid{};
pm::getCurrentPidTid(&pid, &tid);
if (config::get_title_blacklist(tid)) {
this->msg =
"Title is blacklisted!\n"
"Exit to use sys-tune";
return;
}
Result rc = tuneInitialize();
// not found can happen if the service isn't started
// connection refused can happen is the service was terminated by pmshell
if (R_VALUE(rc) == KERNELRESULT(NotFound) || R_VALUE(rc) == KERNELRESULT(ConnectionRefused)) {
u64 pid = 0;
const NcmProgramLocation programLocation{
.program_id = 0x4200000000000000,
.storageID = NcmStorageId_None,
};
rc = pmshellInitialize();
if (R_SUCCEEDED(rc)) {
rc = pmshellLaunchProgram(0, &programLocation, &pid);
pmshellExit();
}
if (R_FAILED(rc) || pid == 0) {
this->fail = rc;
this->msg = " Failed to\n"
"launch sysmodule";
return;
}
svcSleepThread(500'000'000ULL);
rc = tuneInitialize();
}
if (R_FAILED(rc)) {
this->msg = "Something went wrong:";
this->fail = rc;
return;
}
if (R_FAILED(sdmc::Open())) {
this->msg = "Failed sdmc::Open()";
return;
}
u32 api;
if (R_FAILED(tuneGetApiVersion(&api)) || api != TUNE_API_VERSION) {
this->msg = " Unsupported\n"
"sys-tune version!";
}
}
void exitServices() override {
sdmc::Close();
pm::Exit();
tuneExit();
}
std::unique_ptr<tsl::Gui> loadInitialGui() override {
if (this->msg) {
return std::make_unique<ErrorGui>(this->msg, this->fail);
} else {
return std::make_unique<MainGui>();
}
}
};
int main(int argc, char **argv) {
return tsl::loop<SysTuneOverlay>(argc, argv);
}