mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-27 09:32:30 -06:00
core/file_sys: Allow exefs mods to be read from mods path
The original path (file_name.exefsdir) is still supported, but alternatively users can choose to put exefs patches in the same place as LayeredFS files (`load/mods/<Title ID>/exefs`).
This commit is contained in:
parent
8a570bf00c
commit
91e5a39a08
1 changed files with 25 additions and 10 deletions
|
@ -513,7 +513,13 @@ Loader::ResultStatus NCCHContainer::ApplyCodePatch(std::vector<u8>& code) const
|
||||||
std::string path;
|
std::string path;
|
||||||
bool (*patch_fn)(const std::vector<u8>& patch, std::vector<u8>& code);
|
bool (*patch_fn)(const std::vector<u8>& patch, std::vector<u8>& code);
|
||||||
};
|
};
|
||||||
const std::array<PatchLocation, 2> patch_paths{{
|
|
||||||
|
const auto mods_path =
|
||||||
|
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
||||||
|
ncch_header.program_id);
|
||||||
|
const std::array<PatchLocation, 4> patch_paths{{
|
||||||
|
{mods_path + "exefs/code.ips", Patch::ApplyIpsPatch},
|
||||||
|
{mods_path + "exefs/code.bps", Patch::ApplyBpsPatch},
|
||||||
{filepath + ".exefsdir/code.ips", Patch::ApplyIpsPatch},
|
{filepath + ".exefsdir/code.ips", Patch::ApplyIpsPatch},
|
||||||
{filepath + ".exefsdir/code.bps", Patch::ApplyBpsPatch},
|
{filepath + ".exefsdir/code.bps", Patch::ApplyBpsPatch},
|
||||||
}};
|
}};
|
||||||
|
@ -552,8 +558,16 @@ Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name,
|
||||||
else
|
else
|
||||||
return Loader::ResultStatus::Error;
|
return Loader::ResultStatus::Error;
|
||||||
|
|
||||||
std::string section_override = filepath + ".exefsdir/" + override_name;
|
const auto mods_path =
|
||||||
FileUtil::IOFile section_file(section_override, "rb");
|
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
||||||
|
ncch_header.program_id);
|
||||||
|
std::array<std::string, 2> override_paths{{
|
||||||
|
mods_path + "exefs/" + override_name,
|
||||||
|
filepath + ".exefsdir/" + override_name,
|
||||||
|
}};
|
||||||
|
|
||||||
|
for (const auto& path : override_paths) {
|
||||||
|
FileUtil::IOFile section_file(path, "rb");
|
||||||
|
|
||||||
if (section_file.IsOpen()) {
|
if (section_file.IsOpen()) {
|
||||||
auto section_size = section_file.GetSize();
|
auto section_size = section_file.GetSize();
|
||||||
|
@ -561,10 +575,11 @@ Loader::ResultStatus NCCHContainer::LoadOverrideExeFSSection(const char* name,
|
||||||
|
|
||||||
section_file.Seek(0, SEEK_SET);
|
section_file.Seek(0, SEEK_SET);
|
||||||
if (section_file.ReadBytes(&buffer[0], section_size) == section_size) {
|
if (section_file.ReadBytes(&buffer[0], section_size) == section_size) {
|
||||||
LOG_WARNING(Service_FS, "File {} overriding built-in ExeFS file", section_override);
|
LOG_WARNING(Service_FS, "File {} overriding built-in ExeFS file", path);
|
||||||
return Loader::ResultStatus::Success;
|
return Loader::ResultStatus::Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Loader::ResultStatus::ErrorNotUsed;
|
return Loader::ResultStatus::ErrorNotUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue