Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9261 from AdmiralCurtiss/shop-logs
WiiUtils: Create Wii Shop log files when installing a WAD.
  • Loading branch information
leoetlino committed Nov 19, 2020
2 parents 59c362d + 83c235b commit 7e9a2dc
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Source/Core/Core/WiiUtils.cpp
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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<u8, 32> 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;
}

Expand Down

0 comments on commit 7e9a2dc

Please sign in to comment.