Skip to content

Commit

Permalink
Do PtpConnect internally during PtpOpen, since some games (ie. The Wa…
Browse files Browse the repository at this point in the history
…rriors) seems to do PtpSend immediately after PtpOpen without trying to PtpConnect first.
  • Loading branch information
anr2me committed Jan 24, 2021
1 parent 938d752 commit 9bd638c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Core/HLE/sceNetAdhoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ int NetAdhocGameMode_DeleteMaster();
int NetAdhocctl_ExitGameMode();
static int sceNetAdhocPdpSend(int id, const char* mac, u32 port, void* data, int len, int timeout, int flag);
static int sceNetAdhocPdpRecv(int id, void* addr, void* port, void* buf, void* dataLength, u32 timeout, int flag);
static int sceNetAdhocPtpConnect(int id, int timeout, int flag);


void __NetAdhocShutdown() {
Expand Down Expand Up @@ -555,6 +556,10 @@ int DoBlockingPtpSend(int uid, AdhocSocketRequest& req, s64& result) {

DEBUG_LOG(SCENET, "sceNetAdhocPtpSend[%i:%u]: Sent %u bytes to %s:%u\n", req.id, ptpsocket.lport, ret, mac2str(&ptpsocket.paddr).c_str(), ptpsocket.pport);

// Set to Established on successful Send when an attempt to Connect was initiated
if (ptpsocket.state == ADHOC_PTP_STATE_SYN_SENT)
ptpsocket.state = ADHOC_PTP_STATE_ESTABLISHED;

// Return Success
result = 0;
}
Expand Down Expand Up @@ -604,6 +609,10 @@ int DoBlockingPtpRecv(int uid, AdhocSocketRequest& req, s64& result) {
if (peer != NULL) peer->last_recv = CoreTiming::GetGlobalTimeUsScaled();
peerlock.unlock();

// Set to Established on successful Recv when an attempt to Connect was initiated
if (ptpsocket.state == ADHOC_PTP_STATE_SYN_SENT)
ptpsocket.state = ADHOC_PTP_STATE_ESTABLISHED;

result = 0;
}
else if (ret == SOCKET_ERROR && (sockerr == EAGAIN || sockerr == EWOULDBLOCK)) {
Expand Down Expand Up @@ -3191,6 +3200,9 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac,
// Switch to non-blocking for futher usage
changeBlockingMode(tcpsocket, 1);

// Initiate PtpConnect (ie. The Warrior seems to try to PtpSend right after PtpOpen without trying to PtpConnect first)
sceNetAdhocPtpConnect(i + 1, rexmt_cnt, 1);

// Return PTP Socket Pointer
return hleLogDebug(SCENET, i + 1, "success");
}
Expand Down Expand Up @@ -3810,7 +3822,7 @@ static int sceNetAdhocPtpSend(int id, u32 dataAddr, u32 dataSizeAddr, int timeou
socket->nonblocking = flag;

// Connected Socket
if (ptpsocket.state == ADHOC_PTP_STATE_ESTABLISHED) {
if (ptpsocket.state == ADHOC_PTP_STATE_ESTABLISHED || ptpsocket.state == ADHOC_PTP_STATE_SYN_SENT) {
// Valid Arguments
if (data != NULL && len != NULL && *len > 0) {
// Schedule Timeout Removal
Expand Down Expand Up @@ -3844,6 +3856,10 @@ static int sceNetAdhocPtpSend(int id, u32 dataAddr, u32 dataSizeAddr, int timeou

DEBUG_LOG(SCENET, "sceNetAdhocPtpSend[%i:%u]: Sent %u bytes to %s:%u\n", id, ptpsocket.lport, sent, mac2str(&ptpsocket.paddr).c_str(), ptpsocket.pport);

// Set to Established on successful Send when an attempt to Connect was initiated
if (ptpsocket.state == ADHOC_PTP_STATE_SYN_SENT)
ptpsocket.state = ADHOC_PTP_STATE_ESTABLISHED;

// Return Success
return 0;
}
Expand Down Expand Up @@ -3909,7 +3925,7 @@ static int sceNetAdhocPtpRecv(int id, u32 dataAddr, u32 dataSizeAddr, int timeou
auto& ptpsocket = socket->data.ptp;
socket->nonblocking = flag;

if (ptpsocket.state == ADHOC_PTP_STATE_ESTABLISHED) {
if (ptpsocket.state == ADHOC_PTP_STATE_ESTABLISHED || ptpsocket.state == ADHOC_PTP_STATE_SYN_SENT) {
// Schedule Timeout Removal
//if (flag) timeout = 0;

Expand Down Expand Up @@ -3962,6 +3978,10 @@ static int sceNetAdhocPtpRecv(int id, u32 dataAddr, u32 dataSizeAddr, int timeou

DEBUG_LOG(SCENET, "sceNetAdhocPtpRecv[%i:%u]: Received %u bytes from %s:%u\n", id, ptpsocket.lport, received, mac2str(&ptpsocket.paddr).c_str(), ptpsocket.pport);

// Set to Established on successful Recv when an attempt to Connect was initiated
if (ptpsocket.state == ADHOC_PTP_STATE_SYN_SENT)
ptpsocket.state = ADHOC_PTP_STATE_ESTABLISHED;

// Return Success
return 0;
}
Expand Down

0 comments on commit 9bd638c

Please sign in to comment.