cfg: Update preferred region data on-demand. (#7206)

This commit is contained in:
Steveice10 2023-11-24 23:10:58 -08:00 committed by GitHub
parent 68e6a2185d
commit c0ecdb689d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 66 additions and 59 deletions

View file

@ -91,6 +91,14 @@ public:
*/
virtual FileType GetFileType() = 0;
/**
* Returns the preferred region codes of this file
* @return A vector of the preferred region codes
*/
[[nodiscard]] virtual std::span<const u32> GetPreferredRegions() const {
return {};
}
/**
* Load the application and return the created Process instance
* @param process The newly created process.

View file

@ -196,8 +196,7 @@ void AppLoader_NCCH::ParseRegionLockoutInfo(u64 program_id) {
return;
}
auto cfg = Service::CFG::GetModule(Core::System::GetInstance());
ASSERT_MSG(cfg, "CFG Module missing!");
preferred_regions.clear();
std::vector<u8> smdh_buffer;
if (ReadIcon(smdh_buffer) == ResultStatus::Success && smdh_buffer.size() >= sizeof(SMDH)) {
@ -205,19 +204,16 @@ void AppLoader_NCCH::ParseRegionLockoutInfo(u64 program_id) {
std::memcpy(&smdh, smdh_buffer.data(), sizeof(SMDH));
u32 region_lockout = smdh.region_lockout;
constexpr u32 REGION_COUNT = 7;
std::vector<u32> regions;
for (u32 region = 0; region < REGION_COUNT; ++region) {
if (region_lockout & 1) {
regions.push_back(region);
preferred_regions.push_back(region);
}
region_lockout >>= 1;
}
cfg->SetPreferredRegionCodes(regions);
} else {
const auto region = Core::GetSystemTitleRegion(program_id);
if (region.has_value()) {
const std::array regions{region.value()};
cfg->SetPreferredRegionCodes(regions);
preferred_regions.push_back(region.value());
}
}
}

View file

@ -30,6 +30,10 @@ public:
return IdentifyType(file);
}
[[nodiscard]] std::span<const u32> GetPreferredRegions() const override {
return preferred_regions;
}
ResultStatus Load(std::shared_ptr<Kernel::Process>& process) override;
std::pair<std::optional<u32>, ResultStatus> LoadCoreVersion() override;
@ -87,6 +91,8 @@ private:
FileSys::NCCHContainer update_ncch;
FileSys::NCCHContainer* overlay_ncch;
std::vector<u32> preferred_regions;
std::string filepath;
};