From b1844a87531d6ef6d494b41297240892cd184998 Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Fri, 2 Sep 2022 09:14:55 +0200 Subject: [PATCH 1/4] Fix online for NA console logins (#147) This is just a quick fix. In the future we can look into avoiding hardcoded firmware version numbers. On the console it gets read from some system file --- src/Cemu/napi/napi_act.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Cemu/napi/napi_act.cpp b/src/Cemu/napi/napi_act.cpp index 9638dbba..b9a9c16c 100644 --- a/src/Cemu/napi/napi_act.cpp +++ b/src/Cemu/napi/napi_act.cpp @@ -61,7 +61,7 @@ namespace NAPI return true; } - void _ACTSetCommonHeaderParameters(CurlRequestHelper& req) + void _ACTSetCommonHeaderParameters(CurlRequestHelper& req, AuthInfo& authInfo) { req.addHeaderField("X-Nintendo-Platform-ID", "1"); req.addHeaderField("X-Nintendo-Device-Type", "2"); @@ -71,7 +71,10 @@ namespace NAPI req.addHeaderField("Accept", "*/*"); - req.addHeaderField("X-Nintendo-System-Version", "0260"); + if(authInfo.region == CafeConsoleRegion::USA) + req.addHeaderField("X-Nintendo-System-Version", "0270"); + else + req.addHeaderField("X-Nintendo-System-Version", "0260"); } void _ACTSetDeviceParameters(CurlRequestHelper& req, AuthInfo& authInfo) @@ -143,7 +146,7 @@ namespace NAPI CurlRequestHelper req; req.initate(fmt::format("{}/v1/api/oauth20/access_token/generate", LaunchSettings::GetActURLPrefix()), CurlRequestHelper::SERVER_SSL_CONTEXT::ACT); - _ACTSetCommonHeaderParameters(req); + _ACTSetCommonHeaderParameters(req, authInfo); _ACTSetDeviceParameters(req, authInfo); _ACTSetRegionAndCountryParameters(req, authInfo); req.addHeaderField("X-Nintendo-Device-Cert", authInfo.deviceCertBase64); @@ -229,7 +232,7 @@ namespace NAPI req.initate(fmt::format("{}/v1/api/people/@me/profile", LaunchSettings::GetActURLPrefix()), CurlRequestHelper::SERVER_SSL_CONTEXT::ACT); - _ACTSetCommonHeaderParameters(req); + _ACTSetCommonHeaderParameters(req, authInfo); _ACTSetDeviceParameters(req, authInfo); // get oauth2 token @@ -295,7 +298,7 @@ namespace NAPI // do request CurlRequestHelper req; req.initate(fmt::format("{}/v1/api/provider/nex_token/@me?game_server_id={:08X}", LaunchSettings::GetActURLPrefix(), serverId), CurlRequestHelper::SERVER_SSL_CONTEXT::ACT); - _ACTSetCommonHeaderParameters(req); + _ACTSetCommonHeaderParameters(req, authInfo); _ACTSetDeviceParameters(req, authInfo); _ACTSetRegionAndCountryParameters(req, authInfo); req.addHeaderField("X-Nintendo-FPD-Version", "0000"); @@ -448,7 +451,7 @@ namespace NAPI // do request CurlRequestHelper req; req.initate(fmt::format("{}/v1/api/provider/service_token/@me?client_id={}", LaunchSettings::GetActURLPrefix(), clientId), CurlRequestHelper::SERVER_SSL_CONTEXT::ACT); - _ACTSetCommonHeaderParameters(req); + _ACTSetCommonHeaderParameters(req, authInfo); _ACTSetDeviceParameters(req, authInfo); _ACTSetRegionAndCountryParameters(req, authInfo); req.addHeaderField("X-Nintendo-FPD-Version", "0000"); @@ -519,7 +522,7 @@ namespace NAPI // do request CurlRequestHelper req; req.initate(fmt::format("{}/v1/api/admin/mapped_ids?input_type=user_id&output_type=pid&input={}", LaunchSettings::GetActURLPrefix(), nnid), CurlRequestHelper::SERVER_SSL_CONTEXT::ACT); - _ACTSetCommonHeaderParameters(req); + _ACTSetCommonHeaderParameters(req, authInfo); _ACTSetDeviceParameters(req, authInfo); _ACTSetRegionAndCountryParameters(req, authInfo); req.addHeaderField("X-Nintendo-FPD-Version", "0000"); From a3b1af4e3d687e95b229bfe2f0f9818957fc4236 Mon Sep 17 00:00:00 2001 From: bitscher Date: Fri, 2 Sep 2022 00:32:33 -0700 Subject: [PATCH 2/4] Add SIGINT handler on posix systems (#145) --- src/Common/CMakeLists.txt | 3 +- .../ExceptionHandler_posix.cpp | 36 +++++++++++++++++++ ...Handler.cpp => ExceptionHandler_win32.cpp} | 35 ------------------ src/gui/CemuApp.cpp | 7 ---- 4 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 src/Common/ExceptionHandler/ExceptionHandler_posix.cpp rename src/Common/ExceptionHandler/{ExceptionHandler.cpp => ExceptionHandler_win32.cpp} (96%) diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index a1d5b8ab..e7535795 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -11,18 +11,19 @@ target_sources(CemuCommon PRIVATE windows/platform.cpp windows/platform.h + ExceptionHandler/ExceptionHandler_win32.cpp ) else() target_sources(CemuCommon PRIVATE unix/platform.cpp unix/platform.h + ExceptionHandler/ExceptionHandler_posix.cpp ) endif() target_sources(CemuCommon PRIVATE - ExceptionHandler/ExceptionHandler.cpp ExceptionHandler/ExceptionHandler.h ) diff --git a/src/Common/ExceptionHandler/ExceptionHandler_posix.cpp b/src/Common/ExceptionHandler/ExceptionHandler_posix.cpp new file mode 100644 index 00000000..2f18c2d7 --- /dev/null +++ b/src/Common/ExceptionHandler/ExceptionHandler_posix.cpp @@ -0,0 +1,36 @@ +#include +#include + +void handler_SIGSEGV(int sig) +{ + printf("SIGSEGV!\n"); + + void *array[32]; + size_t size; + + // get void*'s for all entries on the stack + size = backtrace(array, 32); + + // print out all the frames to stderr + fprintf(stderr, "Error: signal %d:\n", sig); + backtrace_symbols_fd(array, size, STDERR_FILENO); + exit(1); +} + +void handler_SIGINT(int sig) +{ + /* + * Received when pressing CTRL + C in a console + * Ideally should be exiting cleanly after saving settings but currently + * there's no clean exit pathway (at least on linux) and exiting the app + * by any mean ends up with a SIGABRT from the standard library destroying + * threads. + */ + exit(0); +} + +void ExceptionHandler_init() +{ + signal(SIGSEGV, handler_SIGSEGV); + signal(SIGINT, handler_SIGINT); +} diff --git a/src/Common/ExceptionHandler/ExceptionHandler.cpp b/src/Common/ExceptionHandler/ExceptionHandler_win32.cpp similarity index 96% rename from src/Common/ExceptionHandler/ExceptionHandler.cpp rename to src/Common/ExceptionHandler/ExceptionHandler_win32.cpp index 48a99033..25dca26f 100644 --- a/src/Common/ExceptionHandler/ExceptionHandler.cpp +++ b/src/Common/ExceptionHandler/ExceptionHandler_win32.cpp @@ -1,12 +1,6 @@ #include "Common/precompiled.h" #include "Cafe/CafeSystem.h" -#if BOOST_OS_LINUX || BOOST_OS_MACOS -#include -#include -#endif - -#if BOOST_OS_WINDOWS #include #include #include @@ -16,16 +10,11 @@ #include "Cafe/OS/libs/coreinit/coreinit_Thread.h" #include "Cafe/HW/Espresso/PPCState.h" -#endif - extern uint32 currentBaseApplicationHash; extern uint32 currentUpdatedApplicationHash; -#if BOOST_OS_WINDOWS - LONG handleException_SINGLE_STEP(PEXCEPTION_POINTERS pExceptionInfo) { - return EXCEPTION_CONTINUE_SEARCH; } @@ -416,27 +405,3 @@ void ExceptionHandler_init() AddVectoredExceptionHandler(1, VectoredExceptionHandler); SetErrorMode(SEM_FAILCRITICALERRORS); } -#else - -void handler_SIGSEGV(int sig) -{ - printf("SIGSEGV!\n"); - - void *array[32]; - size_t size; - - // get void*'s for all entries on the stack - size = backtrace(array, 32); - - // print out all the frames to stderr - fprintf(stderr, "Error: signal %d:\n", sig); - backtrace_symbols_fd(array, size, STDERR_FILENO); - exit(1); -} - -void ExceptionHandler_init() -{ - signal(SIGSEGV, handler_SIGSEGV); -} - -#endif \ No newline at end of file diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index 37a40bab..17e31f7a 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -399,11 +399,4 @@ void CemuApp::ActivateApp(wxActivateEvent& event) event.Skip(); } -extern "C" -{ - CemuApp& wxGetAppWrapper() - { - return *static_cast(wxApp::GetInstance()); - }; -} From 86e1a2227c6a98d0a8253e1bb0ce11b176bb2ff0 Mon Sep 17 00:00:00 2001 From: Crementif <26669564+Crementif@users.noreply.github.com> Date: Fri, 2 Sep 2022 09:46:19 +0200 Subject: [PATCH 3/4] nn_act: Fix account endianness (#141) Also adds some code for enabling multi-user support inside apps maybe, but it's probably hardcoded in more places since Cemu currently only shows the active account. --- src/Cafe/Account/Account.cpp | 4 ++-- src/Cafe/IOSU/legacy/iosu_act.cpp | 11 ++++++++++- src/Cafe/IOSU/legacy/iosu_act.h | 2 +- src/Cafe/OS/libs/nn_act/nn_act.cpp | 8 +++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Cafe/Account/Account.cpp b/src/Cafe/Account/Account.cpp index b8d3d52e..f370c815 100644 --- a/src/Cafe/Account/Account.cpp +++ b/src/Cafe/Account/Account.cpp @@ -29,7 +29,7 @@ typedef struct /* +0x0C */ uint8 ukn0C[0xA]; /* +0x16 */ uint8 ukn16[2]; /* +0x18 */ uint16 ukn18; - /* +0x1A */ uint16be miiName[10]; + /* +0x1A */ uint16le miiName[10]; /* +0x2E */ uint16 ukn2E; /* +0x30 */ uint8 ukn30[96 - 0x30]; }FFLData_t; @@ -102,7 +102,7 @@ Account::Account(uint32 persistent_id, std::wstring_view mii_name) FFLData_t* fflData = (FFLData_t*)m_mii_data.data(); const auto tmp_name = GetMiiName(); memset(fflData->miiName, 0, sizeof(fflData->miiName)); - std::copy(tmp_name.cbegin(), tmp_name.cend(), fflData->miiName); + std::copy(tmp_name.begin(), tmp_name.end(), fflData->miiName); // calculate checksum uint32 crcCounter = 0; diff --git a/src/Cafe/IOSU/legacy/iosu_act.cpp b/src/Cafe/IOSU/legacy/iosu_act.cpp index feacbfc0..852dbfba 100644 --- a/src/Cafe/IOSU/legacy/iosu_act.cpp +++ b/src/Cafe/IOSU/legacy/iosu_act.cpp @@ -48,7 +48,7 @@ typedef struct char country[8]; // Mii FFLData_t miiData; - uint16be miiNickname[ACT_NICKNAME_LENGTH]; + uint16le miiNickname[ACT_NICKNAME_LENGTH]; }actAccountData_t; #define IOSU_ACT_ACCOUNT_MAX_COUNT (0xC) @@ -103,6 +103,15 @@ void iosuAct_loadAccounts() const auto& first_acc = Account::GetAccount(persistent_id); FillAccountData(first_acc, online_enabled, counter); ++counter; + // enable multiple accounts for cafe functions (badly tested) + //for (const auto& account : Account::GetAccounts()) + //{ + // if (first_acc.GetPersistentId() != account.GetPersistentId()) + // { + // FillAccountData(account, online_enabled, counter); + // ++counter; + // } + //} cemuLog_force(L"IOSU_ACT: using account {} in first slot", first_acc.GetMiiName()); diff --git a/src/Cafe/IOSU/legacy/iosu_act.h b/src/Cafe/IOSU/legacy/iosu_act.h index 8d644d2f..04dd579f 100644 --- a/src/Cafe/IOSU/legacy/iosu_act.h +++ b/src/Cafe/IOSU/legacy/iosu_act.h @@ -25,7 +25,7 @@ typedef struct /* +0x0C */ uint8 ukn0C[0xA]; /* +0x16 */ uint8 ukn16[2]; /* +0x18 */ uint16 ukn18; - /* +0x1A */ uint16be miiName[MII_FFL_NAME_LENGTH]; + /* +0x1A */ uint16le miiName[MII_FFL_NAME_LENGTH]; /* +0x2E */ uint16 ukn2E; /* +0x30 */ uint8 ukn30[MII_FFL_STORAGE_SIZE-0x30]; }FFLData_t; diff --git a/src/Cafe/OS/libs/nn_act/nn_act.cpp b/src/Cafe/OS/libs/nn_act/nn_act.cpp index a349da5c..9ca33754 100644 --- a/src/Cafe/OS/libs/nn_act/nn_act.cpp +++ b/src/Cafe/OS/libs/nn_act/nn_act.cpp @@ -138,11 +138,9 @@ void nnActExport_GetNumOfAccounts(PPCInterpreter_t* hCPU) void nnActExport_IsSlotOccupied(PPCInterpreter_t* hCPU) { forceLogDebug_printf("nn_act.IsSlotOccupied(%d)\n", hCPU->gpr[3]); - sint32 slotIndex = (sint32)hCPU->gpr[3] - 1; // first slot is 1 - bool isOccupied = false; - if( slotIndex == 0 ) - isOccupied = true; - osLib_returnFromFunction(hCPU, isOccupied?1:0); + ppcDefineParamU8(slot, 0); + + osLib_returnFromFunction(hCPU, nn::act::GetPersistentIdEx(slot) != 0 ? 1 : 0); } uint32 GetAccountIdEx(char* accountId, uint8 slot) From b1e92f1779e4f98a4f50b59c918f919ab36f663b Mon Sep 17 00:00:00 2001 From: bitscher Date: Fri, 2 Sep 2022 02:01:17 -0700 Subject: [PATCH 4/4] Fix more UI asserts (#146) --- src/gui/components/wxGameList.cpp | 3 ++- src/gui/debugger/SymbolCtrl.cpp | 6 ++++-- .../windows/TextureRelationViewer/TextureRelationWindow.cpp | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gui/components/wxGameList.cpp b/src/gui/components/wxGameList.cpp index 35f7dfd1..25ec35f4 100644 --- a/src/gui/components/wxGameList.cpp +++ b/src/gui/components/wxGameList.cpp @@ -243,7 +243,8 @@ void wxGameList::SetStyle(Style style, bool save) g_config.Save(); } - ApplyGameListColumnWidths(); + if (style == Style::kList) + ApplyGameListColumnWidths(); } long wxGameList::GetStyleFlags(Style style) const diff --git a/src/gui/debugger/SymbolCtrl.cpp b/src/gui/debugger/SymbolCtrl.cpp index 394c64f4..d9adaa32 100644 --- a/src/gui/debugger/SymbolCtrl.cpp +++ b/src/gui/debugger/SymbolCtrl.cpp @@ -73,7 +73,8 @@ void SymbolListCtrl::OnGameLoaded() rplSymbolStorage_unlockSymbolMap(); SetItemCount(m_data.size()); - RefreshItems(GetTopItem(), GetTopItem() + GetCountPerPage() + 1); + if (m_data.size() > 0) + RefreshItems(GetTopItem(), std::min(m_data.size() - 1, GetTopItem() + GetCountPerPage() + 1)); } wxString SymbolListCtrl::OnGetItemText(long item, long column) const @@ -159,5 +160,6 @@ void SymbolListCtrl::ChangeListFilter(std::string filter) } } SetItemCount(visible_entries); - RefreshItems(GetTopItem(), GetTopItem() + GetCountPerPage() + 1); + if (visible_entries > 0) + RefreshItems(GetTopItem(), std::min(visible_entries - 1, GetTopItem() + GetCountPerPage() + 1)); } \ No newline at end of file diff --git a/src/gui/windows/TextureRelationViewer/TextureRelationWindow.cpp b/src/gui/windows/TextureRelationViewer/TextureRelationWindow.cpp index 8d5c02a1..5a42691e 100644 --- a/src/gui/windows/TextureRelationViewer/TextureRelationWindow.cpp +++ b/src/gui/windows/TextureRelationViewer/TextureRelationWindow.cpp @@ -372,7 +372,9 @@ void TextureRelationViewerWindow::RefreshTextureList() } } textureRelationListA->Thaw(); - textureRelationListA->EnsureVisible(scrollPos + textureRelationListA->GetCountPerPage() - 1); + long itemCount = textureRelationListA->GetItemCount(); + if (itemCount > 0) + textureRelationListA->EnsureVisible(std::min(itemCount - 1, scrollPos + textureRelationListA->GetCountPerPage() - 1)); } void TextureRelationViewerWindow::OnTextureListRightClick(wxMouseEvent& event) @@ -383,4 +385,4 @@ void TextureRelationViewerWindow::OnTextureListRightClick(wxMouseEvent& event) void TextureRelationViewerWindow::Close() { this->Destroy(); -} \ No newline at end of file +}