diff --git a/Source/Core/Core/WiiUtils.cpp b/Source/Core/Core/WiiUtils.cpp index 667fe0e663..f8ff946abb 100644 --- a/Source/Core/Core/WiiUtils.cpp +++ b/Source/Core/Core/WiiUtils.cpp @@ -36,6 +36,7 @@ #include "Core/IOS/ES/Formats.h" #include "Core/IOS/FS/FileSystem.h" #include "Core/IOS/IOS.h" +#include "Core/IOS/Uids.h" #include "Core/SysConf.h" #include "DiscIO/DiscExtractor.h" #include "DiscIO/Enums.h" @@ -57,6 +58,7 @@ static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, const auto tmd = wad.GetTMD(); const auto es = ios.GetES(); + const auto fs = ios.GetFS(); IOS::HLE::Device::ES::Context context; IOS::HLE::ReturnCode ret; @@ -99,6 +101,38 @@ static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, return false; } + // Under normal conditions, these two log files are created by the Wii Shop channel at some point + // during the process of downloading a game, and some games (eg. Mega Man 9) refuse to load DLC if + // they are not present. So ensure they exist and create them if they don't. + const bool shop_logs_exist = [&] { + const std::array dummy_data{}; + for (const std::string& path : {"/shared2/ec/shopsetu.log", "/shared2/succession/shop.log"}) + { + constexpr IOS::HLE::FS::Mode rw_mode = IOS::HLE::FS::Mode::ReadWrite; + if (fs->CreateFullPath(IOS::SYSMENU_UID, IOS::SYSMENU_GID, path, 0, + {rw_mode, rw_mode, rw_mode}) != IOS::HLE::FS::ResultCode::Success) + { + return false; + } + + const auto old_handle = fs->OpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, path, rw_mode); + if (old_handle) + continue; + + const auto new_handle = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, path, + {rw_mode, rw_mode, rw_mode}); + if (!new_handle || !new_handle->Write(dummy_data.data(), dummy_data.size())) + return false; + } + return true; + }(); + + if (!shop_logs_exist) + { + PanicAlertFmtT("WAD installation failed: Could not create Wii Shop log files."); + return false; + } + return true; }