diff --git a/Core/Config.cpp b/Core/Config.cpp index d182a1ab32..89b515b550 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -684,6 +684,7 @@ static ConfigSetting systemParamSettings[] = { ConfigSetting("NickName", &g_Config.sNickName, "PPSSPP", true, true), ConfigSetting("proAdhocServer", &g_Config.proAdhocServer, "coldbird.net", true, true), ConfigSetting("MacAddress", &g_Config.sMACAddress, &CreateRandMAC, true, true), + ConfigSetting("PortOffset", &g_Config.iPortOffset, 0, true, true), ReportedConfigSetting("Language", &g_Config.iLanguage, &DefaultSystemParamLanguage, true, true), ConfigSetting("TimeFormat", &g_Config.iTimeFormat, PSP_SYSTEMPARAM_TIME_FORMAT_24HR, true, true), ConfigSetting("DateFormat", &g_Config.iDateFormat, PSP_SYSTEMPARAM_DATE_FORMAT_YYYYMMDD, true, true), diff --git a/Core/Config.h b/Core/Config.h index 3333dd3602..df58435160 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -363,6 +363,7 @@ public: std::string sNickName; std::string proAdhocServer; std::string sMACAddress; + int iPortOffset; int iLanguage; int iTimeFormat; int iDateFormat; diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index 6285ff101c..b57a711218 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -31,6 +31,7 @@ #include "proAdhoc.h" #include "i18n/i18n.h" +uint16_t portOffset = g_Config.iPortOffset; uint32_t fakePoolSize = 0; SceNetAdhocMatchingContext * contexts = NULL; int one = 1; diff --git a/Core/HLE/proAdhoc.h b/Core/HLE/proAdhoc.h index b8a0d97d5e..27f4e48d1d 100644 --- a/Core/HLE/proAdhoc.h +++ b/Core/HLE/proAdhoc.h @@ -795,6 +795,7 @@ extern SceNetAdhocPdpStat * pdp[255]; extern SceNetAdhocPtpStat * ptp[255]; extern std::map adhocctlHandlers; +extern uint16_t portOffset; extern uint32_t fakePoolSize; extern SceNetAdhocMatchingContext * contexts; extern int one; diff --git a/Core/HLE/sceNet.cpp b/Core/HLE/sceNet.cpp index 996b9df313..db6ba8d0ab 100644 --- a/Core/HLE/sceNet.cpp +++ b/Core/HLE/sceNet.cpp @@ -52,6 +52,7 @@ static void __ResetInitNetLib() { } void __NetInit() { + portOffset = g_Config.iPortOffset; //net::Init(); #ifdef _MSC_VER WSADATA data; diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 0ab82f607c..5c7c5c55d4 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -276,7 +276,7 @@ static int sceNetAdhocPdpCreate(const char *mac, u32 port, int bufferSize, u32 u addr.sin_addr.s_addr = INADDR_ANY; //if (port < 7) addr.sin_port = htons(port + 1341); else // <= 443 - addr.sin_port = htons(port); // This not safe in any way... + addr.sin_port = htons(port + portOffset ); // This not safe in any way... // The port might be under 1024 (ie. GTA:VCS use port 1, Ford Street Racing use port 0 (UNUSED_PORT), etc) and already used by other application/host OS, should we add 1024 to the port whenever it tried to use an already used port? // Bound Socket to local Port @@ -303,7 +303,7 @@ static int sceNetAdhocPdpCreate(const char *mac, u32 port, int bufferSize, u32 u // Fill in Data internal->id = usocket; internal->laddr = *saddr; - internal->lport = getLocalPort(usocket); //should use the port given to the socket (in case it's UNUSED_PORT port) isn't? + internal->lport = getLocalPort(usocket) - portOffset; //should use the port given to the socket (in case it's UNUSED_PORT port) isn't? internal->rcv_sb_cc = bufferSize; // Link Socket to Translator ID @@ -427,7 +427,7 @@ static int sceNetAdhocPdpSend(int id, const char *mac, u32 port, void *data, int // Fill in Target Structure sockaddr_in target; target.sin_family = AF_INET; - target.sin_port = htons(dport); + target.sin_port = htons(dport + portOffset); // Get Peer IP if (resolveMAC((SceNetEtherAddr *)daddr, (uint32_t *)&target.sin_addr.s_addr)) { @@ -495,7 +495,7 @@ static int sceNetAdhocPdpSend(int id, const char *mac, u32 port, void *data, int sockaddr_in target; target.sin_family = AF_INET; target.sin_addr.s_addr = peer->ip_addr; - target.sin_port = htons(dport); + target.sin_port = htons(dport + portOffset); // Send Data changeBlockingMode(socket->id, flag); @@ -633,7 +633,7 @@ static int sceNetAdhocPdpRecv(int id, void *addr, void * port, void *buf, void * if (resolveIP(sin.sin_addr.s_addr, &mac)) { // Provide Sender Information *saddr = mac; - *sport = ntohs(sin.sin_port); + *sport = ntohs(sin.sin_port) - portOffset; // Save Length *len = received; @@ -1639,7 +1639,7 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac, } // Valid Ports - if (!isPTPPortInUse(sport) && dport != 0) { + if (!isPTPPortInUse(sport) /*&& dport != 0*/) { // Valid Arguments if (bufsize > 0 && rexmt_int > 0 && rexmt_cnt > 0) { // Create Infrastructure Socket @@ -1659,14 +1659,14 @@ static int sceNetAdhocPtpOpen(const char *srcmac, int sport, const char *dstmac, // addr.sin_len = sizeof(addr); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons(sport); + addr.sin_port = htons(sport + portOffset); // Bound Socket to local Port if (bind(tcpsocket, (sockaddr *)&addr, sizeof(addr)) == 0) { - // Update sport with the port assigned by bind + // Update sport with the port assigned binternal->lport = ntohs(local.sin_port)y bind socklen_t len = sizeof(addr); if (getsockname(tcpsocket, (sockaddr *)&addr, &len) == 0) { - sport = ntohs(addr.sin_port); + sport = ntohs(addr.sin_port) - portOffset; } // Allocate Memory @@ -1850,11 +1850,11 @@ static int sceNetAdhocPtpAccept(int id, u32 peerMacAddrPtr, u32 peerPortPtr, int // Copy Local Address Data to Structure getLocalMac(&internal->laddr); - internal->lport = ntohs(local.sin_port); + internal->lport = ntohs(local.sin_port) - portOffset; // Copy Peer Address Data to Structure internal->paddr = mac; - internal->pport = ntohs(peeraddr.sin_port); + internal->pport = ntohs(peeraddr.sin_port) - portOffset; // Set Connected State internal->state = ADHOC_PTP_STATE_ESTABLISHED; @@ -1942,7 +1942,7 @@ static int sceNetAdhocPtpConnect(int id, int timeout, int flag) { // Setup Target Address // sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; - sin.sin_port = htons(socket->pport); + sin.sin_port = htons(socket->pport + portOffset); // Grab Peer IP if (resolveMAC(&socket->paddr, (uint32_t *)&sin.sin_addr.s_addr)) { @@ -2131,7 +2131,7 @@ static int sceNetAdhocPtpListen(const char *srcmac, int sport, int bufsize, int sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; - addr.sin_port = htons(sport); + addr.sin_port = htons(sport + portOffset); int iResult = 0; // Bound Socket to local Port diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index f99522e3df..fb586e4591 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -477,6 +477,7 @@ void GameSettingsScreen::CreateViews() { #endif networkingSettings->Add(new CheckBox(&g_Config.bEnableAdhocServer, n->T("Enable built-in PRO Adhoc Server", "Enable built-in PRO Adhoc Server"))); networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sMACAddress, n->T("Change Mac Address"), nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeMacAddress); + networkingSettings->Add(new PopupSliderChoice(&g_Config.iPortOffset, 0, 60000, n->T("Port offset", "Port offset(0 = PSP compatibility)"), 100, screenManager())); ViewGroup *toolsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); toolsScroll->SetTag("GameSettingsTools");