From fbdf9ba153d6f409bd27ea1c160f9814a0e05393 Mon Sep 17 00:00:00 2001 From: skidau Date: Wed, 5 Oct 2011 00:22:51 +1100 Subject: [PATCH] Added preliminary support for ES_LAUNCH (Wii Multi-boot games) by using HLE to hijack the OSBootDol function. Metroid Prime Trilogy is working. Wii Sports+Wii Sports Resort is not working. Any games which can be played using the dol replacement trick should work here. Suspect that the DOL's are meant to receive an argument list which has not been catered for in this code. This probably also means that the Metroid Prime Trilogy games are locked in Veteran difficulty for the time-being. --- Data/Sys/totaldb.dsy | Bin 722980 -> 723252 bytes Source/Core/Core/Src/Boot/Boot.cpp | 13 ++++++++ Source/Core/Core/Src/HLE/HLE.cpp | 4 ++- Source/Core/Core/Src/HLE/HLE_Misc.cpp | 44 ++++++++++++++++++++++++++ Source/Core/Core/Src/HLE/HLE_Misc.h | 1 + 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Data/Sys/totaldb.dsy b/Data/Sys/totaldb.dsy index 790a942eaefc071dfcad998bcc985dc239e2582f..a1c9683c9f57ca74ba2693c818d474dcb4761b2e 100644 GIT binary patch delta 93 zcmZ27L1)V(9mZpgjIE4}t&B{qjLfZ!EUk>Jt&D7~jO?w99IcF;t&Ch-8M&1?gx(l# iIrxQvfgwKLKiDZhzr-bfy5cg{G9mRgzM~HqF~kAJ`x}M; delta 45 zcmdloNoUCf9mXS#jIE4}t&B{qjLfZ!EUk>Jt&D7~jO?w99IcF;t&Ch-8M&1?03h)S Ac>n+a diff --git a/Source/Core/Core/Src/Boot/Boot.cpp b/Source/Core/Core/Src/Boot/Boot.cpp index be82d217dc..228d10b8a8 100644 --- a/Source/Core/Core/Src/Boot/Boot.cpp +++ b/Source/Core/Core/Src/Boot/Boot.cpp @@ -257,6 +257,19 @@ bool CBoot::BootUp() EmulatedBS2(_StartupPara.bWii); } + // Scan for common HLE functions + if (!_StartupPara.bEnableDebugging) + { + PPCAnalyst::FindFunctions(0x80000000, 0x81800000, &g_symbolDB); + SignatureDB db; + if (db.Load((File::GetSysDirectory() + TOTALDB).c_str())) + { + db.Apply(&g_symbolDB); + } + HLE::PatchFunctions(); + g_symbolDB.Clear(); + } + /* Try to load the symbol map if there is one, and then scan it for and eventually replace code */ if (LoadMapFromFilename(_StartupPara.m_strFilename, gameID)) diff --git a/Source/Core/Core/Src/HLE/HLE.cpp b/Source/Core/Core/Src/HLE/HLE.cpp index 84c6b2eb86..671a9e0a3a 100644 --- a/Source/Core/Core/Src/HLE/HLE.cpp +++ b/Source/Core/Core/Src/HLE/HLE.cpp @@ -27,6 +27,7 @@ #include "HLE_OS.h" #include "HLE_Misc.h" +#include "IPC_HLE/WII_IPC_HLE_Device_es.h" namespace HLE { @@ -93,7 +94,8 @@ static const SPatch OSPatches[] = // { "GXPeekARGB", HLE_Misc::GXPeekARGB}, // Name doesn't matter, installed in CBoot::BootUp() - { "HBReload", HLE_Misc::HBReload }, + { "HBReload", HLE_Misc::HBReload }, + { "__OSBootDol", HLE_Misc::OSBootDol }, }; static const SPatch OSBreakPoints[] = diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.cpp b/Source/Core/Core/Src/HLE/HLE_Misc.cpp index d69bf09680..bc625c9d2d 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.cpp +++ b/Source/Core/Core/Src/HLE/HLE_Misc.cpp @@ -22,6 +22,12 @@ #include "../PowerPC/PowerPC.h" #include "../HW/Memmap.h" #include "../Host.h" +#include "IPC_HLE/WII_IPC_HLE_Device_DI.h" +#include "ConfigManager.h" +#include "VolumeCreator.h" +#include "Filesystem.h" +#include "../Boot/Boot_DOL.h" +#include "IPC_HLE/WII_IPC_HLE_Device_usb.h" namespace HLE_Misc { @@ -282,4 +288,42 @@ void HBReload() Host_Message(WM_USER_STOP); } + +void OSBootDol() +{ + std::string dol; + + u32 r28 = GPR(28); + Memory::GetString(dol, r28); + + DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(SConfig::GetInstance().m_LastFilename.c_str()); + DiscIO::IFileSystem* pFileSystem = DiscIO::CreateFileSystem(pVolume); + + size_t fileSize = (size_t) pFileSystem->GetFileSize(dol.substr(1).c_str()); + u8* dolFile = new u8[fileSize]; + if (dolFile) + { + pFileSystem->ReadFile(dol.substr(1).c_str(), dolFile, fileSize); + CDolLoader dolLoader(dolFile, fileSize); + dolLoader.Load(); + PowerPC::ppcState.iCache.Reset(); + + static CWII_IPC_HLE_Device_usb_oh1_57e_305* s_Usb = GetUsbPointer(); + for (unsigned int i = 0; i < 4; i++) + { + if (s_Usb->m_WiiMotes[i].IsConnected()) + { + s_Usb->m_WiiMotes[i].Activate(false); + s_Usb->m_WiiMotes[i].Activate(true); + } + else + { + s_Usb->m_WiiMotes[i].Activate(false); + } + } + + NPC = dolLoader.GetEntryPoint() | 0x80000000; + } +} + } diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.h b/Source/Core/Core/Src/HLE/HLE_Misc.h index 6c932258a7..f831e5b600 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.h +++ b/Source/Core/Core/Src/HLE/HLE_Misc.h @@ -39,6 +39,7 @@ namespace HLE_Misc void FZ_sqrt_internal(); void FZ_rsqrt_internal(); void HBReload(); + void OSBootDol(); } #endif