Working again with last Atmosphere and libnx

This commit is contained in:
XorTroll 2021-06-15 22:22:54 +02:00
parent 2cdb53e922
commit e3f25760d7
9 changed files with 45 additions and 40 deletions

@ -1 +1 @@
Subproject commit 17960517bad5d2d07effb28b744ac8d907d571e0
Subproject commit 11ea38a7d7cc5d449ce9102544773b73e4586842

View file

@ -39,6 +39,7 @@ namespace {
bool g_AlbumAppletLaunchFlag = false;
bool g_MenuRestartFlag = false;
bool g_HbTargetOpenedAsApplication = false;
bool g_AppletActive = false;
AppletOperationMode g_OperationMode;
u8 *g_UsbViewerBuffer = nullptr;
u8 *g_UsbViewerReadBuffer = nullptr;
@ -91,14 +92,14 @@ void __libnx_initheap() {
void __appInit() {
ams::hos::InitializeForStratosphere();
ams::sm::DoWithSession([]() {
UL_ASSERT(appletInitialize());
UL_ASSERT(fsInitialize());
UL_ASSERT(nsInitialize());
UL_ASSERT(pminfoInitialize());
UL_ASSERT(ldrShellInitialize());
UL_ASSERT(pmshellInitialize());
});
UL_AMS_ASSERT(ams::sm::Initialize());
UL_ASSERT(appletInitialize());
UL_ASSERT(fsInitialize());
UL_ASSERT(nsInitialize());
UL_ASSERT(pminfoInitialize());
UL_ASSERT(ldrShellInitialize());
UL_ASSERT(pmshellInitialize());
fsdevMountSdmc();
}
@ -133,8 +134,8 @@ namespace {
appletStartSleepSequence(true);
}
inline Result LaunchMenu(dmi::MenuStartMode stmode, dmi::DaemonStatus status) {
return ecs::RegisterLaunchAsApplet(g_Config.menu_program_id, static_cast<u32>(stmode), "/ulaunch/bin/uMenu", &status, sizeof(status));
inline Result LaunchMenu(dmi::MenuStartMode st_mode, dmi::DaemonStatus status) {
return ecs::RegisterLaunchAsApplet(g_Config.menu_program_id, static_cast<u32>(st_mode), "/ulaunch/bin/uMenu", &status, sizeof(status));
}
void HandleHomeButton() {
@ -209,7 +210,7 @@ namespace {
u32 raw_msg = 0;
R_TRY(appletGetMessage(&raw_msg));
auto msg = static_cast<os::AppletMessage>(raw_msg);
const auto msg = static_cast<os::AppletMessage>(raw_msg);
switch(msg) {
case os::AppletMessage::HomeButton: {
HandleHomeButton();
@ -236,7 +237,7 @@ namespace {
void HandleMenuMessage() {
if(am::LibraryAppletIsMenu()) {
char web_url[500] = {0};
char web_url[500] = {};
u64 app_id = 0;
hb::HbTargetParams ipt = {};
dmi::daemon::ReceiveCommand([&](dmi::DaemonMessage msg, dmi::daemon::DaemonScopedStorageReader &reader) -> Result {
@ -361,7 +362,7 @@ namespace {
}
}
void UsbViewerRGBAThread(void *arg) {
void UsbViewerRGBAThread(void*) {
while(true) {
bool tmp_flag;
appletGetLastForegroundCaptureImageEx(g_UsbViewerReadBuffer, RawRGBAScreenBufferSize, &tmp_flag);
@ -370,7 +371,7 @@ namespace {
}
}
void UsbViewerJPEGThread(void *arg) {
void UsbViewerJPEGThread(void*) {
while(true) {
u64 tmp_size;
capsscCaptureJpegScreenShot(&tmp_size, g_UsbViewerReadBuffer, RawRGBAScreenBufferSize, ViLayerStack_Default, UINT64_MAX);
@ -399,7 +400,7 @@ namespace {
HandleMenuMessage();
bool sth_done = false;
// A valid version in this g_Config is always >= 0x20000
// A valid version will always be >= 0x20000
if(g_WebAppletLaunchFlag.version > 0) {
if(!am::LibraryAppletIsActive()) {
UL_ASSERT(am::WebAppletStart(&g_WebAppletLaunchFlag));
@ -460,7 +461,10 @@ namespace {
sth_done = true;
}
}
if(!sth_done) {
const auto applet_active_old = g_AppletActive;
g_AppletActive = am::LibraryAppletIsActive();
if(!sth_done && !applet_active_old) {
// If nothing was done, but nothing is active... An application or applet might have crashed, terminated, failed to launch...
// No matter what is it, we reopen Menu in launch-error mode.
if(!am::ApplicationIsActive() && !am::LibraryAppletIsActive()) {
@ -520,10 +524,8 @@ namespace {
am::LibraryAppletSetMenuAppletId(am::LibraryAppletGetAppletIdForProgramId(g_Config.menu_program_id));
if(g_Config.viewer_usb_enabled) {
ams::sm::DoWithSession([]() {
UL_ASSERT(usbCommsInitialize());
UL_ASSERT(capsscInitialize());
});
UL_ASSERT(usbCommsInitialize());
UL_ASSERT(capsscInitialize());
PrepareUsbViewer();
UL_ASSERT(LaunchUsbViewerThread());

View file

@ -10,7 +10,7 @@ namespace {
ams::os::Mutex g_ServerAllocatorLock(false);
void GlobalManagerThread(void*) {
UL_ASSERT((g_GlobalManager.RegisterServer(ipc::PortIndex_PrivateService, ipc::PrivateServiceName, ipc::MaxPrivateSessions).GetValue()));
UL_AMS_ASSERT(g_GlobalManager.RegisterServer(ipc::PortIndex_PrivateService, ipc::PrivateServiceName, ipc::MaxPrivateSessions));
// UL_ASSERT(g_GlobalManager.RegisterServer<ipc::IPublicService>(PublicServiceName, MaxPublicSessions).GetValue());
g_GlobalManager.LoopProcess();
@ -31,8 +31,9 @@ namespace ipc {
ams::Result ServerManager::OnNeedsToAccept(int port_index, Server *server) {
switch(port_index) {
case PortIndex_PrivateService:
case PortIndex_PrivateService: {
return this->AcceptImpl(server, MakeShared<ams::sf::ul::IPrivateService, ipc::PrivateService>());
}
AMS_UNREACHABLE_DEFAULT_CASE();
}
}

View file

@ -12,7 +12,7 @@ namespace ipc {
u64 program_id = 0;
R_TRY(pminfoGetProgramId(&program_id, client_pid.process_id.value));
auto last_menu_program_id = am::LibraryAppletGetProgramIdForAppletId(am::LibraryAppletGetMenuAppletId());
const auto last_menu_program_id = am::LibraryAppletGetProgramIdForAppletId(am::LibraryAppletGetMenuAppletId());
// If Menu hasn't been launched it's program ID will be 0/invalid, thus a != check wouldn't be enough
// If any of the IDs is invalid, something unexpected is happening...
if((last_menu_program_id == 0) || (program_id == 0) || (program_id != last_menu_program_id)) {

View file

@ -34,7 +34,7 @@ namespace hb {
return argv;
}
inline static HbTargetParams Create(const std::string &nro_path, const std::string &nro_argv, bool target_once) {
static inline HbTargetParams Create(const std::string &nro_path, const std::string &nro_argv, bool target_once) {
HbTargetParams params = {};
params.magic = UL_HB_HBTARGET_MAGIC_U32;
strcpy(params.nro_path, nro_path.c_str());

View file

@ -27,17 +27,17 @@ namespace os {
u8 data[0x3F4];
static inline constexpr SystemAppletMessage Create(GeneralChannelMessage msg) {
SystemAppletMessage sams = {};
sams.magic = Magic;
sams.general_channel_message = msg;
return sams;
return SystemAppletMessage {
.magic = Magic,
.general_channel_message = msg
};
}
};
// 1024 bytes are always sent, so let's read it all.
static_assert(sizeof(SystemAppletMessage) == 0x400, "System applet message");
// TODO: actual names N uses?
enum class AppletMessage : u32 {
Invalid,
Exit = 4,

View file

@ -76,8 +76,10 @@ inline __attribute__((noreturn)) void OnAssertionFailed(const char *log_buf, siz
#define UL_ASSERT(expr) ({ \
const auto _tmp_rc = (expr); \
if(R_FAILED(_tmp_rc)) { \
char logbuf[UL_ASSERT_LOG_LEN] = {0}; \
char logbuf[UL_ASSERT_LOG_LEN] = {}; \
sprintf(logbuf, "%s asserted 0x%X...", #expr, _tmp_rc); \
OnAssertionFailed(logbuf, UL_ASSERT_LOG_LEN, _tmp_rc); \
} \
})
#define UL_AMS_ASSERT(expr) UL_ASSERT(ams::Result(expr).GetValue())

View file

@ -45,9 +45,9 @@ namespace os {
}
bool IsConsoleCharging() {
auto cht = ChargerType_None;
psmGetChargerType(&cht);
return cht > ChargerType_None;
auto charger_type = PsmChargerType_Unconnected;
psmGetChargerType(&charger_type);
return charger_type > PsmChargerType_Unconnected;
}
std::string GetFirmwareVersion() {
@ -63,7 +63,7 @@ namespace os {
auto local_time = localtime(&time_val);
auto h = local_time->tm_hour;
auto min = local_time->tm_min;
char str[0x10] = {0};
char str[0x10] = {};
sprintf(str, "%02d:%02d", h, min);
return str;
}

View file

@ -43,20 +43,20 @@ namespace util
}
std::string FormatResultDisplay(Result rc) {
char res[0x20] = {0};
char res[0x20] = {};
sprintf(res, "%04d-%04d", R_MODULE(rc) + 2000, R_DESCRIPTION(rc));
return std::string(res);
return res;
}
std::string FormatResultHex(Result rc) {
char res[0x20] = {0};
char res[0x20] = {};
sprintf(res, "0x%X", rc);
return std::string(res);
return res;
}
std::string FormatResult(Result rc) {
auto desc = RES_DESCRIPTION(rc);
std::string fmt = "(" + FormatResultDisplay(rc) + ")";
auto fmt = "(" + FormatResultDisplay(rc) + ")";
if(!desc.empty()) {
fmt += " ";
fmt += desc;