diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index e43ffc52d4..ca23a754bc 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -690,14 +690,15 @@ void StateFlags::UpdateChecksum() checksum = std::accumulate(flag_data.cbegin(), flag_data.cend(), 0U); } -void UpdateStateFlags(std::function update_function) +void UpdateStateFlags(IOS::HLE::EmulationKernel* const ios, + std::function update_function) { - CreateSystemMenuTitleDirs(); + CreateSystemMenuTitleDirs(ios->GetESCore()); const std::string file_path = Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/" WII_STATE; - const auto fs = Core::System::GetInstance().GetIOS()->GetFS(); + const auto file_system = ios->GetFS(); constexpr IOS::HLE::FS::Mode rw_mode = IOS::HLE::FS::Mode::ReadWrite; - const auto file = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, file_path, - {rw_mode, rw_mode, rw_mode}); + const auto file = file_system->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, file_path, + {rw_mode, rw_mode, rw_mode}); if (!file) return; @@ -712,10 +713,9 @@ void UpdateStateFlags(std::function update_function) file->Write(&state, 1); } -void CreateSystemMenuTitleDirs() +void CreateSystemMenuTitleDirs(const IOS::HLE::ESCore& es_core) { - const auto& es = Core::System::GetInstance().GetIOS()->GetESCore(); - es.CreateTitleDirectories(Titles::SYSTEM_MENU, IOS::SYSMENU_GID); + es_core.CreateTitleDirectories(Titles::SYSTEM_MENU, IOS::SYSMENU_GID); } void AddRiivolutionPatches(BootParameters* boot_params, diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index f892ee7c75..b31eda3a08 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -32,6 +32,12 @@ namespace File class IOFile; } +namespace IOS::HLE +{ +class EmulationKernel; +class ESCore; +} // namespace IOS::HLE + namespace IOS::HLE::FS { class FileSystem; @@ -222,13 +228,14 @@ struct StateFlags // Reads the state file from the NAND, then calls the passed update function to update the struct, // and finally writes the updated state file to the NAND. -void UpdateStateFlags(std::function update_function); +void UpdateStateFlags(IOS::HLE::EmulationKernel* ios, + std::function update_function); /// Create title directories for the system menu (if needed). /// /// Normally, this is automatically done by ES when the System Menu is installed, /// but we cannot rely on this because we don't require any system titles to be installed. -void CreateSystemMenuTitleDirs(); +void CreateSystemMenuTitleDirs(const IOS::HLE::ESCore& es_core); void AddRiivolutionPatches(BootParameters* boot_params, std::vector riivolution_patches); diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 8742b30e4c..d70ee3bd85 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -371,13 +372,15 @@ bool CBoot::SetupWiiMemory(Core::System& system, IOS::HLE::IOSC::ConsoleType con auto entryPos = region_settings.find(SConfig::GetInstance().m_region); RegionSetting region_setting = entryPos->second; + IOS::HLE::EmulationKernel* const ios = system.GetIOS(); + std::string serno; std::string model = "RVL-001(" + region_setting.area + ")"; - CreateSystemMenuTitleDirs(); + CreateSystemMenuTitleDirs(ios->GetESCore()); const std::string settings_file_path(Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/" WII_SETTING); - const auto fs = system.GetIOS()->GetFS(); + const auto fs = ios->GetFS(); { Common::SettingsBuffer data; const auto file = fs->OpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, settings_file_path, @@ -514,14 +517,14 @@ bool CBoot::SetupWiiMemory(Core::System& system, IOS::HLE::IOSC::ConsoleType con return true; } -static void WriteEmptyPlayRecord() +static void WriteEmptyPlayRecord(IOS::HLE::EmulationKernel* const ios) { - CreateSystemMenuTitleDirs(); + CreateSystemMenuTitleDirs(ios->GetESCore()); const std::string file_path = Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/play_rec.dat"; - const auto fs = Core::System::GetInstance().GetIOS()->GetFS(); + const auto file_system = ios->GetFS(); constexpr IOS::HLE::FS::Mode rw_mode = IOS::HLE::FS::Mode::ReadWrite; - const auto playrec_file = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, file_path, - {rw_mode, rw_mode, rw_mode}); + const auto playrec_file = file_system->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, + file_path, {rw_mode, rw_mode, rw_mode}); if (!playrec_file) return; std::vector empty_record(0x80); @@ -546,8 +549,10 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu if (!tmd.IsValid()) return false; - WriteEmptyPlayRecord(); - UpdateStateFlags([](StateFlags* state) { + IOS::HLE::EmulationKernel* const pre_boot_ios = system.GetIOS(); + + WriteEmptyPlayRecord(pre_boot_ios); + UpdateStateFlags(pre_boot_ios, [](StateFlags* const state) { state->flags = 0xc1; state->type = 0xff; state->discstate = 0x01; @@ -576,11 +581,12 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu ios_override >= 0 ? Titles::IOS(static_cast(ios_override)) : tmd.GetIOSId(); const auto console_type = volume.GetTicket(data_partition).GetConsoleType(); - if (!SetupWiiMemory(system, console_type) || !system.GetIOS()->BootIOS(ios_id)) + if (!SetupWiiMemory(system, console_type) || !pre_boot_ios->BootIOS(ios_id)) return false; - auto di = - std::static_pointer_cast(system.GetIOS()->GetDeviceByName("/dev/di")); + IOS::HLE::EmulationKernel* const post_boot_ios = system.GetIOS(); + + auto di = std::static_pointer_cast(post_boot_ios->GetDeviceByName("/dev/di")); di->InitializeIfFirstTime(); di->ChangePartition(data_partition); @@ -613,7 +619,7 @@ bool CBoot::EmulatedBS2_Wii(Core::System& system, const Core::CPUThreadGuard& gu // Warning: This call will set incorrect running game metadata if our volume parameter // doesn't point to the same disc as the one that's inserted in the emulated disc drive! - system.GetIOS()->GetESDevice()->DIVerify(tmd, volume.GetTicket(partition)); + post_boot_ios->GetESDevice()->DIVerify(tmd, volume.GetTicket(partition)); return true; } diff --git a/Source/Core/Core/Boot/Boot_WiiWAD.cpp b/Source/Core/Core/Boot/Boot_WiiWAD.cpp index 8b3d780335..cb1e041731 100644 --- a/Source/Core/Core/Boot/Boot_WiiWAD.cpp +++ b/Source/Core/Core/Boot/Boot_WiiWAD.cpp @@ -18,11 +18,12 @@ bool CBoot::BootNANDTitle(Core::System& system, const u64 title_id) { - UpdateStateFlags([](StateFlags* state) { + IOS::HLE::EmulationKernel* const ios = system.GetIOS(); + UpdateStateFlags(ios, [](StateFlags* const state) { state->type = 0x04; // TYPE_NANDBOOT }); - auto es = system.GetIOS()->GetESDevice(); + auto es = ios->GetESDevice(); const IOS::ES::TicketReader ticket = es->GetCore().FindSignedTicket(title_id); auto console_type = IOS::HLE::IOSC::ConsoleType::Retail; if (ticket.IsValid())