Merge pull request #19897 from hrydgard/dont-connect-to-adhoc

Infrastructure: Don't connect to adhoc unless infra-dns.json tells us to
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2025-01-20 22:19:19 +01:00
commit b189688689
12 files changed
+143 -41

No files matched your search

-1
View File
@@ -177,7 +177,6 @@ int PSPNetconfDialog::Update(int animSpeed) {
else if (state == PSP_NET_APCTL_STATE_DISCONNECTED) {
// When connecting with infrastructure, simulate a connection using the first network configuration entry.
if (connResult < 0) {
// connResult = sceNetApctlConnect(1);
connResult = hleCall(sceNetApctl, int, sceNetApctlConnect, 1);
}
}
+4 -4
View File
@@ -1372,7 +1372,7 @@ int friendFinder() {
if (metasocket == (int)INVALID_SOCKET && netAdhocctlInited && isAdhocctlNeedLogin) {
if (g_Config.bEnableWlan) {
if (initNetwork(&product_code) == 0) {
networkInited = true;
g_adhocServerConnected = true;
INFO_LOG(Log::sceNet, "FriendFinder: Network [RE]Initialized");
// At this point we are most-likely not in a Group within the Adhoc Server, so we should probably reset AdhocctlState
adhocctlState = ADHOCCTL_STATE_DISCONNECTED;
@@ -1380,7 +1380,7 @@ int friendFinder() {
isAdhocctlBusy = false;
}
else {
networkInited = false;
g_adhocServerConnected = false;
shutdown((int)metasocket, SD_BOTH);
closesocket((int)metasocket);
metasocket = (int)INVALID_SOCKET;
@@ -1390,7 +1390,7 @@ int friendFinder() {
// Prevent retrying to Login again unless it was on demand
isAdhocctlNeedLogin = false;
if (networkInited) {
if (g_adhocServerConnected) {
// Ping Server
now = time_now_d() * 1000000.0; // Use time_now_d()*1000000.0 instead of CoreTiming::GetGlobalTimeUsScaled() if the game gets disconnected from AdhocServer too soon when FPS wasn't stable
// original code : ((sceKernelGetSystemTimeWide() - lastping) >= ADHOCCTL_PING_TIMEOUT)
@@ -1406,7 +1406,7 @@ int friendFinder() {
if (iResult == SOCKET_ERROR) {
ERROR_LOG(Log::sceNet, "FriendFinder: Socket Error (%i) when sending OPCODE_PING", error);
if (error != EAGAIN && error != EWOULDBLOCK) {
networkInited = false;
g_adhocServerConnected = false;
shutdown((int)metasocket, SD_BOTH);
closesocket((int)metasocket);
metasocket = (int)INVALID_SOCKET;
+1 -1
View File
@@ -1673,7 +1673,7 @@ static u32 sceMpegFinish()
// TODO: Need to properly hook module load/unload for this to work right.
//return ERROR_MPEG_NOT_YET_INIT;
} else {
INFO_LOG(Log::ME, "sceMpegFinish(...)");
INFO_LOG(Log::ME, "sceMpegFinish()");
__VideoPmpShutdown();
}
isMpegInit = false;
+36 -17
View File
@@ -69,7 +69,7 @@ std::string defaultNetSSID = "Wifi"; // fake AP/hotspot
int netApctlInfoId = 0;
SceNetApctlInfoInternal netApctlInfo;
bool netApctlInited;
bool g_netApctlInited;
u32 netApctlState;
u32 apctlProdCodeAddr = 0;
u32 apctlThreadHackAddr = 0;
@@ -185,6 +185,7 @@ bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) {
dns->revivalTeamURL = revived.getStringOr("url", "");
}
}
dns->connectAdHocForGrouping = def.getBool("connect_adhoc_for_grouping", false);
}
const JsonNode *games = root.getArray("games");
@@ -242,6 +243,7 @@ bool LoadDNSForGameID(std::string_view gameID, InfraDNSConfig *dns) {
dns->gameName = game.getStringOr("name", "");
dns->dns = game.getStringOr("dns", dns->dns.c_str());
dns->dyn_dns = game.getStringOr("dyn_dns", "");
dns->connectAdHocForGrouping = game.getBool("connect_adhoc_for_grouping", dns->connectAdHocForGrouping);
if (game.hasChild("domains", JSON_OBJECT)) {
const JsonGet domains = game.getDict("domains");
for (auto iter : domains.value_) {
@@ -332,7 +334,7 @@ int ScheduleApctlState(int event, int newState, int usec, const char* reason) {
}
void __NetApctlInit() {
netApctlInited = false;
g_netApctlInited = false;
netApctlState = PSP_NET_APCTL_STATE_DISCONNECTED;
apctlStateEvent = CoreTiming::RegisterEvent("__ApctlState", __ApctlState);
apctlHandlers.clear();
@@ -435,11 +437,11 @@ void __NetDoState(PointerWrap &p) {
auto cur_netInited = netInited;
auto cur_netInetInited = netInetInited;
auto cur_netApctlInited = netApctlInited;
auto cur_netApctlInited = g_netApctlInited;
Do(p, netInited);
Do(p, netInetInited);
Do(p, netApctlInited);
Do(p, g_netApctlInited);
Do(p, apctlHandlers);
Do(p, netMallocStat);
if (s < 2) {
@@ -488,7 +490,7 @@ void __NetDoState(PointerWrap &p) {
if (p.mode == p.MODE_READ) {
// Let's not change "Inited" value when Loading SaveState in the middle of multiplayer to prevent memory & port leaks
netApctlInited = cur_netApctlInited;
g_netApctlInited = cur_netApctlInited;
netInetInited = cur_netInetInited;
netInited = cur_netInited;
@@ -1006,7 +1008,7 @@ void NetApctl_InitInfo(int confId) {
}
static int sceNetApctlInit(int stackSize, int initPriority) {
if (netApctlInited) {
if (g_netApctlInited) {
return hleLogError(Log::sceNet, ERROR_NET_APCTL_ALREADY_INITIALIZED);
}
@@ -1038,16 +1040,22 @@ static int sceNetApctlInit(int stackSize, int initPriority) {
memcpy(prodCode->data, discID.c_str(), std::min(ADHOCCTL_ADHOCID_LEN, (int)discID.size()));
}
hleCall(sceNetAdhocctl, int, sceNetAdhocctlInit, stackSize, initPriority, apctlProdCodeAddr);
netApctlInited = true;
// Actually connect sceNetAdhocctl. TODO: Can we move this to sceNetApctlConnect? Would be good because a lot of games call Init but not Connect on startup.
if (g_infraDNSConfig.connectAdHocForGrouping) {
hleCall(sceNetAdhocctl, int, sceNetAdhocctlInit, stackSize, initPriority, apctlProdCodeAddr);
}
g_netApctlInited = true;
return hleLogSuccessInfoI(Log::sceNet, 0);
}
int NetApctl_Term() {
// Note: Since we're borrowing AdhocServer for Grouping purpose, we should cleanup too
NetAdhocctl_Term();
// Should we check the g_infraDNSConfig.connectAdHocForGrouping flag here?
if (g_netApctlInited) {
hleCall(sceNetAdhocctl, int, sceNetAdhocctlTerm);
}
if (apctlProdCodeAddr != 0) {
userMemory.Free(apctlProdCodeAddr);
apctlProdCodeAddr = 0;
@@ -1061,9 +1069,8 @@ int NetApctl_Term() {
apctlThreadID = 0;
}
netApctlInited = false;
g_netApctlInited = false;
netApctlState = PSP_NET_APCTL_STATE_DISCONNECTED;
return 0;
}
@@ -1275,12 +1282,18 @@ int sceNetApctlConnect(int confId) {
// Is this confId is the index to the scanning's result data or sceNetApctlGetBSSDescIDListUser result?
netApctlInfoId = confId;
// Note: We're borrowing AdhocServer for Grouping purpose, so we can simulate Broadcast over the internet just like Adhoc's pro-online implementation
int ret = hleCall(sceNetAdhocctl, int, sceNetAdhocctlConnect, "INFRA");
if (netApctlState == PSP_NET_APCTL_STATE_DISCONNECTED)
// Note: We're borrowing AdhocServer for Grouping purpose, so we can simulate Broadcast over the internet just like Adhoc's pro-online implementation
int ret = 0;
if (g_infraDNSConfig.connectAdHocForGrouping) {
ret = hleCall(sceNetAdhocctl, int, sceNetAdhocctlConnect, "INFRA");
}
if (netApctlState == PSP_NET_APCTL_STATE_DISCONNECTED) {
__UpdateApctlHandlers(0, PSP_NET_APCTL_STATE_JOINING, PSP_NET_APCTL_EVENT_CONNECT_REQUEST, 0);
//hleDelayResult(0, "give time to init/cleanup", adhocEventDelayMS * 1000);
}
// hleDelayResult(0, "give time to init/cleanup", adhocEventDelayMS * 1000);
// TODO: Blocks current thread and wait for a state change to prevent user-triggered connection attempt from causing events to piles up
return hleLogSuccessInfoI(Log::sceNet, 0, "connect = %i", ret);
}
@@ -1289,7 +1302,9 @@ int sceNetApctlDisconnect() {
// Like its 'sister' function sceNetAdhocctlDisconnect, we need to alert Apctl handlers that a disconnect took place
// or else games like Phantasy Star Portable 2 will hang at certain points (e.g. returning to the main menu after trying to connect to PSN).
// Note: Since we're borrowing AdhocServer for Grouping purpose, we should disconnect too
hleCall(sceNetAdhocctl, int, sceNetAdhocctlDisconnect);
if (g_infraDNSConfig.connectAdHocForGrouping) {
hleCall(sceNetAdhocctl, int, sceNetAdhocctlDisconnect);
}
// Discards any pending events so we can disconnect immediately
apctlEvents.clear();
@@ -1302,6 +1317,10 @@ int NetApctl_GetState() {
return netApctlState;
}
bool __NetApctlConnected() {
return netApctlState >= PSP_NET_APCTL_STATE_GOT_IP;
}
static int sceNetApctlGetState(u32 pStateAddr) {
//if (!netApctlInited) return hleLogError(Log::sceNet, ERROR_NET_APCTL_NOT_IN_BSS, "apctl not in bss");
+5 -1
View File
@@ -109,7 +109,7 @@ private:
};
extern bool netInited;
extern bool netApctlInited;
extern bool g_netApctlInited;
extern u32 netApctlState;
extern SceNetApctlInfoInternal netApctlInfo;
extern std::string defaultNetConfigName;
@@ -127,6 +127,8 @@ void __NetDoState(PointerWrap &p);
int NetApctl_GetState();
bool __NetApctlConnected();
int sceNetApctlConnect(int connIndex);
// These return false if allowed to be consistent with the similar function for achievements.
@@ -154,6 +156,8 @@ struct InfraDNSConfig {
std::string revivalTeam;
std::string revivalTeamURL;
bool connectAdHocForGrouping;
};
extern InfraDNSConfig g_infraDNSConfig;
+6 -6
View File
@@ -68,7 +68,7 @@
// TODO: Make accessor functions instead, and throw all this state in a struct.
bool netAdhocInited;
bool netAdhocctlInited;
bool networkInited = false;
bool g_adhocServerConnected = false;
#define DISCOVER_DURATION_US 2000000 // 2 seconds is probably the normal time it takes for PSP to connect to a group (ie. similar to NetconfigDialog time)
u64 netAdhocDiscoverStartTime = 0;
@@ -128,7 +128,6 @@ void ZeroNetAdhocMatchingThreads();
void SaveNetAdhocMatchingInited();
void RestoreNetAdhocMatchingInited();
bool __NetAdhocConnected() {
return netAdhocInited && netAdhocctlInited && (adhocctlState == ADHOCCTL_STATE_CONNECTED || adhocctlState == ADHOCCTL_STATE_GAMEMODE);
}
@@ -371,7 +370,7 @@ static void __AdhocctlNotify(u64 userdata, int cyclesLate) {
}
// Retry until successfully sent. Login packet sent after successfully connected to Adhoc Server (indicated by networkInited), so we're not sending Login again here
if ((req.opcode == OPCODE_LOGIN && !networkInited) || (ret == SOCKET_ERROR && (sockerr == EAGAIN || sockerr == EWOULDBLOCK))) {
if ((req.opcode == OPCODE_LOGIN && !g_adhocServerConnected) || (ret == SOCKET_ERROR && (sockerr == EAGAIN || sockerr == EWOULDBLOCK))) {
u64 now = (u64)(time_now_d() * 1000000.0);
if (now - adhocctlStartTime <= static_cast<u64>(adhocDefaultTimeout) + 500) {
// Try again in another 0.5ms until timedout.
@@ -1278,8 +1277,9 @@ int sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr) {
// FIXME: Returning 0x8002013a (SCE_KERNEL_ERROR_LIBRARY_NOT_YET_LINKED) without adhoc module loaded first?
// FIXME: Sometimes returning 0x80410601 (ERROR_NET_ADHOC_AUTH_ALREADY_INITIALIZED / Library module is already initialized ?) when AdhocctlTerm is not fully done?
if (netAdhocctlInited)
if (netAdhocctlInited) {
return hleLogError(Log::sceNet, ERROR_NET_ADHOCCTL_ALREADY_INITIALIZED);
}
auto product = PSPPointer<SceNetAdhocctlAdhocId>::Create(productAddr);
if (product.IsValid()) {
@@ -1306,7 +1306,7 @@ int sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr) {
// Need to make sure to be connected to Adhoc Server (indicated by networkInited) before returning to prevent GTA VCS failed to create/join a group and unable to see any game room
int us = adhocDefaultDelay;
if (g_Config.bEnableWlan && !networkInited) {
if (g_Config.bEnableWlan && !g_adhocServerConnected) {
AdhocctlRequest dummyreq = { OPCODE_LOGIN, {0} };
return hleLogSuccessOrWarn(Log::sceNet, WaitBlockingAdhocctlSocket(dummyreq, us, "adhocctl init"));
}
@@ -2582,7 +2582,7 @@ int NetAdhocctl_Term() {
//May also need to clear Handlers
adhocctlHandlers.clear();
// Free stuff here
networkInited = false;
g_adhocServerConnected = false;
shutdown((int)metasocket, SD_BOTH);
closesocket((int)metasocket);
metasocket = (int)INVALID_SOCKET;
+3 -2
View File
@@ -106,7 +106,7 @@ void __UpdateAdhocctlHandlers(u32 flags, u32 error);
bool __NetAdhocConnected();
// Called from netdialog
// Called from netdialog (and from sceNetApctl)
// NOTE: use hleCall for sceNet* ones!
int sceNetAdhocctlGetState(u32 ptrToStatus);
int sceNetAdhocctlCreate(const char * groupName);
@@ -116,6 +116,7 @@ int sceNetAdhocctlScan();
int sceNetAdhocctlGetScanInfo(u32 sizeAddr, u32 bufAddr);
int sceNetAdhocctlDisconnect();
int sceNetAdhocctlInit(int stackSize, int prio, u32 productAddr);
int sceNetAdhocctlTerm();
int NetAdhocctl_Term();
int NetAdhocctl_GetState();
@@ -125,7 +126,7 @@ int NetAdhoc_Term();
// May need to use these from sceNet.cpp
extern bool netAdhocInited;
extern bool netAdhocctlInited;
extern bool networkInited;
extern bool g_adhocServerConnected;
extern bool netAdhocGameModeEntered;
extern int netAdhocEnterGameModeTimeout;
extern int adhocDefaultTimeout; //3000000 usec
+1 -1
View File
@@ -117,7 +117,7 @@ class PointerWrap;
extern bool netInited;
extern bool netInetInited;
extern bool netApctlInited;
extern bool g_netApctlInited;
extern u32 netApctlState;
extern SceNetApctlInfoInternal netApctlInfo;
extern std::string defaultNetConfigName;
+1 -5
View File
@@ -67,11 +67,7 @@ static std::mutex g_netResolversLock; // Do we really need this?
static bool g_netResolverInitialized = true;
static int sceNetResolverInit() {
// TODO: Move this to infra-jns.config! This isn't ok.
// However obviously don't remove the mHostToAlias mechanism.
g_Config.mHostToAlias["socomftb2.psp.online.scea.com"] = "67.222.156.250";
g_Config.mHostToAlias["socompsp-prod.muis.pdonline.scea.com"] = "67.222.156.250";
// Hardcoded mHostToAlias entries here have been moved to the infra-dns.json file.
return hleLogSuccessInfoI(Log::sceNet, 0);
}
+8 -2
View File
@@ -44,6 +44,7 @@
#include "Core/HLE/sceUmd.h"
#include "Core/HLE/sceNet.h"
#include "Core/HLE/sceNetInet.h"
#include "Core/HLE/sceNetAdhoc.h"
#include "GPU/GPUCommon.h"
#include "GPU/GPUState.h"
@@ -277,11 +278,12 @@ void GamePauseScreen::update() {
finishNextFrame_ = false;
}
if (netInited != lastNetInited_ || netInetInited != lastNetInetInited_) {
if (netInited != lastNetInited_ || netInetInited != lastNetInetInited_ || lastAdhocServerConnected_ != g_adhocServerConnected) {
INFO_LOG(Log::sceNet, "Network status changed, recreating views");
RecreateViews();
lastNetInetInited_ = netInetInited;
lastNetInited_ = netInited;
lastAdhocServerConnected_ = g_adhocServerConnected;
}
bool mustRunBehind = MustRunBehind();
@@ -384,7 +386,7 @@ void GamePauseScreen::CreateViews() {
}
}
if (netInited) {
if (netInited || g_adhocServerConnected) {
leftColumnItems->Add(new NoticeView(NoticeLevel::INFO, nw->T("Network connected"), ""));
if (!g_infraDNSConfig.revivalTeam.empty() && netInetInited) {
@@ -399,6 +401,10 @@ void GamePauseScreen::CreateViews() {
});
}
}
if (g_adhocServerConnected) {
leftColumnItems->Add(new TextView(std::string(nw->T("AdHoc Server")) + ": " + std::string(nw->T("Connected"))));
}
}
bool achievementsAllowSavestates = !Achievements::HardcoreModeActive() || g_Config.bAchievementsSaveStateInHardcoreMode;
+1
View File
@@ -66,4 +66,5 @@ private:
UI::Button *playButton_ = nullptr;
bool lastNetInited_ = false;
bool lastNetInetInited_ = false;
bool lastAdhocServerConnected_ = false;
};
+77 -1
View File
@@ -133,7 +133,7 @@
},
{
"name": "Ratchet & Clank - Size Matters",
"dns": "67.222.156.251",
"dns": "67.222.156.250",
"other_ids": [
"UCES00420",
"UCUS98633"
@@ -151,6 +151,82 @@
"revival_credits": {
"group": "OutRun2006Tweaks"
}
},
{
"name": "SOCOM Fireteam Bravo",
"known_working_ids": [
"UCKS45021",
"UCUS98615",
"UCES00038"
],
"score": 4,
"domains": {
"socomftb2.psp.online.scea.com": "67.222.156.250",
"socompsp-prod.muis.pdonline.scea.com": "67.222.156.250"
}
},
{
"name": "SOCOM Fireteam Bravo 2",
"known_working_ids": [
"UCUS98645",
"UCES00543"
],
"other_ids": [
"UCKS45043",
"UCUS80171"
],
"score": 4,
"domains": {
"socomftb2.psp.online.scea.com": "67.222.156.250",
"socompsp-prod.muis.pdonline.scea.com": "67.222.156.250"
}
},
{
"name": "SOCOM Tactical Strike",
"known_working_ids": [
"UCUS98649",
"UCES00855"
],
"other_ids": [
"NPUG80220"
],
"score": 3,
"domains": {
"socomftb2.psp.online.scea.com": "67.222.156.250",
"socompsp-prod.muis.pdonline.scea.com": "67.222.156.250"
}
},
{
"name": "Syphon Filter: Dark Mirror",
"known_working_ids": [
"UCUS98641"
],
"score": 5
},
{
"name": "Driver '76",
"known_working_ids": [
"ULUS10235",
"ULES00740"
],
"score": 5,
"connect_adhoc_for_grouping": true
},
{
"name": "Rocky Balboa",
"other_ids": [
"ULES00670"
],
"score": 0,
"connect_adhoc_for_grouping": true
},
{
"name": "Onore no Shinzuru",
"other_ids": [
"ULJM05465"
],
"score": 0,
"connect_adhoc_for_grouping": true
}
]
}