From d67c4f34d110edf3f5d9593f948265ff75fb8111 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jan 2020 19:48:19 -0800 Subject: [PATCH 1/2] Fix crash when launching gamecube games with MIOS (from the Wii menu) --- Source/Core/Core/IOS/DI/DI.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/IOS/DI/DI.cpp b/Source/Core/Core/IOS/DI/DI.cpp index 5a53e76446..f6d8c249c3 100644 --- a/Source/Core/Core/IOS/DI/DI.cpp +++ b/Source/Core/Core/IOS/DI/DI.cpp @@ -526,6 +526,16 @@ std::optional DI::StartImmediateTransfer(const IOCtlRequest& reque return {}; } +static std::shared_ptr GetDevice() +{ + auto ios = IOS::HLE::GetIOS(); + if (!ios) + return nullptr; + auto di = ios->GetDeviceByName("/dev/di"); + // di may be empty, but static_pointer_cast returns empty in that case + return std::static_pointer_cast(di); +} + void DI::InterruptFromDVDInterface(DVDInterface::DIInterruptType interrupt_type) { DIResult result; @@ -544,10 +554,10 @@ void DI::InterruptFromDVDInterface(DVDInterface::DIInterruptType interrupt_type) break; } - auto di = IOS::HLE::GetIOS()->GetDeviceByName("/dev/di"); + auto di = GetDevice(); if (di) { - std::static_pointer_cast(di)->FinishDICommand(result); + di->FinishDICommand(result); } else { @@ -560,9 +570,9 @@ void DI::FinishDICommandCallback(u64 userdata, s64 ticksbehind) { const DIResult result = static_cast(userdata); - auto di = IOS::HLE::GetIOS()->GetDeviceByName("/dev/di"); + auto di = GetDevice(); if (di) - std::static_pointer_cast(di)->FinishDICommand(result); + di->FinishDICommand(result); else PanicAlert("IOS::HLE::Device::DI: Received interrupt from DI when device wasn't registered!"); } @@ -691,12 +701,12 @@ void DI::ChangePartition(const DiscIO::Partition partition) DiscIO::Partition DI::GetCurrentPartition() { - auto di = IOS::HLE::GetIOS()->GetDeviceByName("/dev/di"); + auto di = GetDevice(); // Note that this function is called in Gamecube mode for UpdateRunningGameMetadata, // so both cases are hit in normal circumstances. if (!di) return DiscIO::PARTITION_NONE; - return std::static_pointer_cast(di)->m_current_partition; + return di->m_current_partition; } void DI::InitializeIfFirstTime() From ddba80133a1a2f0c82d23c10197aa23cfb6f0066 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 13 Jan 2020 19:48:46 -0800 Subject: [PATCH 2/2] Fix launching DTK games with MIOS --- Source/Core/Core/IOS/MIOS.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/IOS/MIOS.cpp b/Source/Core/Core/IOS/MIOS.cpp index d7de03d494..e5bb987ea5 100644 --- a/Source/Core/Core/IOS/MIOS.cpp +++ b/Source/Core/Core/IOS/MIOS.cpp @@ -34,7 +34,10 @@ static void ReinitHardware() // IOS clears mem2 and overwrites it with pseudo-random data (for security). std::memset(Memory::m_pEXRAM, 0, Memory::EXRAM_SIZE); // MIOS appears to only reset the DI and the PPC. - DVDInterface::Reset(); + // HACK However, resetting DI will reset the DTK config, which is set by the system menu + // (and not by MIOS), causing games that use DTK to break. Perhaps MIOS doesn't actually + // reset DI fully, in such a way that the DTK config isn't cleared? + // DVDInterface::Reset(); PowerPC::Reset(); Wiimote::ResetAllWiimotes(); // Note: this is specific to Dolphin and is required because we initialised it in Wii mode.