CBoot: Remove calls to System::GetInstance

Use the system argument provided to the boot functions to pass IOS or
its relevant subsystems to functions that previously called
System::GetInstance.
This commit is contained in:
Dentomologist 2025-09-21 17:17:52 -07:00
parent 1625a792e3
commit 63ce58ff9a
4 changed files with 39 additions and 25 deletions

View File

@ -690,14 +690,15 @@ void StateFlags::UpdateChecksum()
checksum = std::accumulate(flag_data.cbegin(), flag_data.cend(), 0U);
}
void UpdateStateFlags(std::function<void(StateFlags*)> update_function)
void UpdateStateFlags(IOS::HLE::EmulationKernel* const ios,
std::function<void(StateFlags*)> 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<void(StateFlags*)> 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,

View File

@ -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<void(StateFlags*)> update_function);
void UpdateStateFlags(IOS::HLE::EmulationKernel* ios,
std::function<void(StateFlags*)> 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<DiscIO::Riivolution::Patch> riivolution_patches);

View File

@ -3,6 +3,7 @@
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
@ -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<u8> 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<u32>(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<IOS::HLE::DIDevice>(system.GetIOS()->GetDeviceByName("/dev/di"));
IOS::HLE::EmulationKernel* const post_boot_ios = system.GetIOS();
auto di = std::static_pointer_cast<IOS::HLE::DIDevice>(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;
}

View File

@ -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())