From edf415be88fa0b8aa4589112a7cc3fb04eb42535 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Sun, 19 Nov 2017 21:49:25 +0100 Subject: [PATCH] Add optional MOHH2 Adhoc hack, also just for a test both MOHH games cross region play, might not work:] --- Core/Config.cpp | 1 + Core/Config.h | 1 + Core/HLE/proAdhoc.cpp | 4 +++- Core/HLE/proAdhocServer.cpp | 15 +++++++++++++++ Core/HLE/sceNetAdhoc.cpp | 8 ++++---- UI/GameSettingsScreen.cpp | 1 + 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 08e609aa5c..37a2584d8f 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -745,6 +745,7 @@ static ConfigSetting systemParamSettings[] = { ConfigSetting("proAdhocServer", &g_Config.proAdhocServer, "localhost", true, true), ConfigSetting("MacAddress", &g_Config.sMACAddress, "", true, true), ConfigSetting("PortOffset", &g_Config.iPortOffset, 0, true, true), + ConfigSetting("MOHH2hack", &g_Config.bMOHH2hack, false, 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 43679cbf70..aad1cefa9d 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -412,6 +412,7 @@ public: std::string sNickName; std::string proAdhocServer; std::string sMACAddress; + bool bMOHH2hack; int iPortOffset; int iLanguage; int iTimeFormat; diff --git a/Core/HLE/proAdhoc.cpp b/Core/HLE/proAdhoc.cpp index cc717774c4..430836bd68 100644 --- a/Core/HLE/proAdhoc.cpp +++ b/Core/HLE/proAdhoc.cpp @@ -1037,7 +1037,7 @@ int friendFinder(){ //_acquireNetworkLock(); // Ping Server - now = real_time_now()*1000000.0; // should be in microseconds, but it seems real_time_now() returns in seconds + now = CoreTiming::GetGlobalTimeUsScaled(); //real_time_now()*1000000.0; // should be in microseconds, but it seems real_time_now() returns in seconds if (now - lastping >= PSP_ADHOCCTL_PING_TIMEOUT) { //100 // We need to use lower interval to prevent getting timeout at Pro Adhoc Server through internet // original code : ((sceKernelGetSystemTimeWide() - lastping) >= ADHOCCTL_PING_TIMEOUT) // Update Ping Time @@ -1083,6 +1083,8 @@ int friendFinder(){ if (rx[0] == OPCODE_CONNECT_BSSID) { INFO_LOG(SCENET, "FriendFinder: Incoming OPCODE_CONNECT_BSSID"); // Enough Data available + if(g_Config.bMOHH2hack) // Really bad, but works around MOHH2 timing issue + sleep_ms(666*10); // Don't hurry, be happy, 5s wasn't enough, let's use a safe number if (rxpos >= (int)sizeof(SceNetAdhocctlConnectBSSIDPacketS2C)) { // Cast Packet SceNetAdhocctlConnectBSSIDPacketS2C * packet = (SceNetAdhocctlConnectBSSIDPacketS2C *)rx; diff --git a/Core/HLE/proAdhocServer.cpp b/Core/HLE/proAdhocServer.cpp index bb1ae5eb39..3c3922abf4 100644 --- a/Core/HLE/proAdhocServer.cpp +++ b/Core/HLE/proAdhocServer.cpp @@ -148,6 +148,20 @@ static const db_crosslink default_crosslinks[] = { { "ULES00566", "ULUS10180" }, { "ULJM05202", "ULUS10180" }, + // Medal of Honor Heroes // untested + { "ULES00557", "ULUS10141" }, + { "ULJM05213", "ULUS10141" }, + { "NPJH50306", "ULUS10141" }, + + // Medal of Honor Heroes 2 // untested + { "ULES00988", "ULUS10310" }, + { "ULAS42120", "ULUS10310" }, + { "ULJM05301", "ULUS10310" }, + { "ULES00955", "ULUS10310" }, + { "ULES00956", "ULUS10310" }, + { "ULJM05430", "ULUS10310" }, + { "NPJH50307", "ULUS10310" }, + // Metal Gear Solid - Peace Walker { "ULES01372", "NPJH50045" }, { "ULUS10509", "NPJH50045" }, @@ -368,6 +382,7 @@ static const db_productid default_productids[] = { { "ULJS00385", "Mahou Shoujo Nanoha A's Portable - The Gears of Destiny" }, { "ULUS10408", "Mana Khemia Student Alliance" }, { "ULUS10141", "Medal Of Honor Heroes" }, + { "ULUS10310", "Medal Of Honor Heroes 2" }, { "NPJH50045", "Metal Gear Solid - Peace Walker" }, { "ULUS10202", "Metal Gear Solid - Portable Ops" }, { "ULUS10290", "Metal Gear Solid - Portable Ops +" }, diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index d404199a71..a0f387f837 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -1796,10 +1796,10 @@ static int sceNetAdhocPtpAccept(int id, u32 peerMacAddrPtr, u32 peerPortPtr, int // Blocking Behaviour if (!flag && newsocket == -1) { // Get Start Time - uint32_t starttime = (uint32_t)(real_time_now()*1000000.0); + uint32_t starttime = (uint32_t)(CoreTiming::GetGlobalTimeUsScaled()); // Retry until Timeout hits - while ((timeout == 0 ||((uint32_t)(real_time_now()*1000000.0) - starttime) < (uint32_t)timeout) && newsocket == -1) { + while ((timeout == 0 ||((uint32_t)(CoreTiming::GetGlobalTimeUsScaled()) - starttime) < (uint32_t)timeout) && newsocket == -1) { // Accept Connection newsocket = accept(socket->id, (sockaddr *)&peeraddr, &peeraddrlen); @@ -1995,14 +1995,14 @@ static int sceNetAdhocPtpConnect(int id, int timeout, int flag) { // Blocking Mode else { // Grab Connection Start Time - uint32_t starttime = (uint32_t)(real_time_now()*1000000.0); + uint32_t starttime = (uint32_t)(CoreTiming::GetGlobalTimeUsScaled()); // Peer Information (for Connection-Polling) sockaddr_in peer; memset(&peer, 0, sizeof(peer)); socklen_t peerlen = sizeof(peer); // Wait for Connection - while ((timeout == 0 || ( (uint32_t)(real_time_now()*1000000.0) - starttime) < (uint32_t)timeout) && getpeername(socket->id, (sockaddr *)&peer, &peerlen) != 0) { + while ((timeout == 0 || ( (uint32_t)(CoreTiming::GetGlobalTimeUsScaled()) - starttime) < (uint32_t)timeout) && getpeername(socket->id, (sockaddr *)&peer, &peerlen) != 0) { // Wait 1ms sleep_ms(1); } diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 8af8f31b72..e6262b5e1c 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -636,6 +636,7 @@ void GameSettingsScreen::CreateViews() { 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())); + networkingSettings->Add(new CheckBox(&g_Config.bMOHH2hack, n->T("Medal of Honor Heroes 2 hack", "Medal of Honor Heroes 2 hack"))); ViewGroup *toolsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); toolsScroll->SetTag("GameSettingsTools");