Respect Config::isConnectedToNetwork when returning connection state

This commit is contained in:
Marcin Mikołajczyk 2025-07-11 18:46:45 +01:00
parent 4aff9de22e
commit 63c23dfcb7
2 changed files with 12 additions and 3 deletions

View File

@ -2,6 +2,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm> #include <algorithm>
#include "common/config.h"
#include "common/logging/log.h"
#include "core/libraries/network/net_ctl_codes.h" #include "core/libraries/network/net_ctl_codes.h"
#include "core/libraries/network/net_ctl_obj.h" #include "core/libraries/network/net_ctl_obj.h"
#include "core/tls.h" #include "core/tls.h"
@ -44,18 +46,22 @@ s32 NetCtlInternal::RegisterNpToolkitCallback(OrbisNetCtlCallbackForNpToolkit fu
void NetCtlInternal::CheckCallback() { void NetCtlInternal::CheckCallback() {
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
const auto event = Config::getIsConnectedToNetwork() ? ORBIS_NET_CTL_EVENT_TYPE_IPOBTAINED
: ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED;
for (const auto [func, arg] : callbacks) { for (const auto [func, arg] : callbacks) {
if (func != nullptr) { if (func != nullptr) {
Core::ExecuteGuest(func, ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED, arg); Core::ExecuteGuest(func, event, arg);
} }
} }
} }
void NetCtlInternal::CheckNpToolkitCallback() { void NetCtlInternal::CheckNpToolkitCallback() {
std::scoped_lock lock{m_mutex}; std::scoped_lock lock{m_mutex};
const auto event = Config::getIsConnectedToNetwork() ? ORBIS_NET_CTL_EVENT_TYPE_IPOBTAINED
: ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED;
for (const auto [func, arg] : nptool_callbacks) { for (const auto [func, arg] : nptool_callbacks) {
if (func != nullptr) { if (func != nullptr) {
Core::ExecuteGuest(func, ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED, arg); Core::ExecuteGuest(func, event, arg);
} }
} }
} }

View File

@ -13,6 +13,7 @@
#endif #endif
#include <common/singleton.h> #include <common/singleton.h>
#include "common/config.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/libraries/error_codes.h" #include "core/libraries/error_codes.h"
#include "core/libraries/libs.h" #include "core/libraries/libs.h"
@ -271,7 +272,9 @@ int PS4_SYSV_ABI sceNetCtlGetScanInfoForSsidScanIpcInt() {
} }
int PS4_SYSV_ABI sceNetCtlGetState(int* state) { int PS4_SYSV_ABI sceNetCtlGetState(int* state) {
*state = ORBIS_NET_CTL_STATE_DISCONNECTED; LOG_DEBUG(Lib_NetCtl, "connected = {}", Config::getIsConnectedToNetwork());
const auto current_state = Config::getIsConnectedToNetwork() ? ORBIS_NET_CTL_STATE_IPOBTAINED : ORBIS_NET_CTL_STATE_DISCONNECTED;
*state = current_state;
return ORBIS_OK; return ORBIS_OK;
} }