diff options
| author | 2018-10-02 08:56:56 -0400 | |
|---|---|---|
| committer | 2018-10-04 12:29:20 -0400 | |
| commit | c1e069c066a609103c6b880585738ecabe48ddd2 (patch) | |
| tree | bf599fa1e774ae098866d50ca5acbaf3441eb16e | |
| parent | fsmitm_romfsbuild: Add support for stubbing and IPS patches in LFS (diff) | |
| download | yuzu-c1e069c066a609103c6b880585738ecabe48ddd2.tar.gz yuzu-c1e069c066a609103c6b880585738ecabe48ddd2.tar.xz yuzu-c1e069c066a609103c6b880585738ecabe48ddd2.zip | |
fsmitm_romfsbuild: Extract stubs and IPS to romfs_ext dir
Diffstat (limited to '')
| -rw-r--r-- | src/core/file_sys/fsmitm_romfsbuild.cpp | 34 | ||||
| -rw-r--r-- | src/core/file_sys/fsmitm_romfsbuild.h | 6 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 13 | ||||
| -rw-r--r-- | src/core/file_sys/romfs.cpp | 4 | ||||
| -rw-r--r-- | src/core/file_sys/romfs.h | 2 |
5 files changed, 38 insertions, 21 deletions
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 4aa8ae369..47b7526c7 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp | |||
| @@ -124,7 +124,7 @@ static u64 romfs_get_hash_table_count(u64 num_entries) { | |||
| 124 | return count; | 124 | return count; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | 127 | void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext, |
| 128 | std::shared_ptr<RomFSBuildDirectoryContext> parent) { | 128 | std::shared_ptr<RomFSBuildDirectoryContext> parent) { |
| 129 | std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; | 129 | std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; |
| 130 | 130 | ||
| @@ -139,15 +139,15 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | |||
| 139 | 139 | ||
| 140 | for (const auto& kv : entries) { | 140 | for (const auto& kv : entries) { |
| 141 | if (kv.second == VfsEntryType::Directory) { | 141 | if (kv.second == VfsEntryType::Directory) { |
| 142 | if (dir->GetSubdirectory(kv.first + ".stub") != nullptr) | ||
| 143 | continue; | ||
| 144 | |||
| 145 | const auto child = std::make_shared<RomFSBuildDirectoryContext>(); | 142 | const auto child = std::make_shared<RomFSBuildDirectoryContext>(); |
| 146 | // Set child's path. | 143 | // Set child's path. |
| 147 | child->cur_path_ofs = parent->path_len + 1; | 144 | child->cur_path_ofs = parent->path_len + 1; |
| 148 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); | 145 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); |
| 149 | child->path = parent->path + "/" + kv.first; | 146 | child->path = parent->path + "/" + kv.first; |
| 150 | 147 | ||
| 148 | if (ext != nullptr && ext->GetFileRelative(child->path + ".stub") != nullptr) | ||
| 149 | continue; | ||
| 150 | |||
| 151 | // Sanity check on path_len | 151 | // Sanity check on path_len |
| 152 | ASSERT(child->path_len < FS_MAX_PATH); | 152 | ASSERT(child->path_len < FS_MAX_PATH); |
| 153 | 153 | ||
| @@ -155,25 +155,28 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | |||
| 155 | child_dirs.push_back(child); | 155 | child_dirs.push_back(child); |
| 156 | } | 156 | } |
| 157 | } else { | 157 | } else { |
| 158 | if (dir->GetFile(kv.first + ".stub") != nullptr) | ||
| 159 | continue; | ||
| 160 | |||
| 161 | const auto child = std::make_shared<RomFSBuildFileContext>(); | 158 | const auto child = std::make_shared<RomFSBuildFileContext>(); |
| 162 | // Set child's path. | 159 | // Set child's path. |
| 163 | child->cur_path_ofs = parent->path_len + 1; | 160 | child->cur_path_ofs = parent->path_len + 1; |
| 164 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); | 161 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); |
| 165 | child->path = parent->path + "/" + kv.first; | 162 | child->path = parent->path + "/" + kv.first; |
| 166 | 163 | ||
| 164 | if (ext != nullptr && ext->GetFileRelative(child->path + ".stub") != nullptr) | ||
| 165 | continue; | ||
| 166 | |||
| 167 | // Sanity check on path_len | 167 | // Sanity check on path_len |
| 168 | ASSERT(child->path_len < FS_MAX_PATH); | 168 | ASSERT(child->path_len < FS_MAX_PATH); |
| 169 | 169 | ||
| 170 | child->source = root_romfs->GetFileRelative(child->path); | 170 | child->source = root_romfs->GetFileRelative(child->path); |
| 171 | 171 | ||
| 172 | if (dir->GetFile(kv.first + ".ips") != nullptr) { | 172 | if (ext != nullptr) { |
| 173 | const auto ips = dir->GetFile(kv.first + ".ips"); | 173 | const auto ips = ext->GetFileRelative(child->path + ".ips"); |
| 174 | auto patched = PatchIPS(child->source, ips); | 174 | |
| 175 | if (patched != nullptr) | 175 | if (ips != nullptr) { |
| 176 | child->source = std::move(patched); | 176 | auto patched = PatchIPS(child->source, ips); |
| 177 | if (patched != nullptr) | ||
| 178 | child->source = std::move(patched); | ||
| 179 | } | ||
| 177 | } | 180 | } |
| 178 | 181 | ||
| 179 | child->size = child->source->GetSize(); | 182 | child->size = child->source->GetSize(); |
| @@ -183,7 +186,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | |||
| 183 | } | 186 | } |
| 184 | 187 | ||
| 185 | for (auto& child : child_dirs) { | 188 | for (auto& child : child_dirs) { |
| 186 | this->VisitDirectory(root_romfs, child); | 189 | this->VisitDirectory(root_romfs, ext, child); |
| 187 | } | 190 | } |
| 188 | } | 191 | } |
| 189 | 192 | ||
| @@ -222,14 +225,15 @@ bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> pare | |||
| 222 | return true; | 225 | return true; |
| 223 | } | 226 | } |
| 224 | 227 | ||
| 225 | RomFSBuildContext::RomFSBuildContext(VirtualDir base_) : base(std::move(base_)) { | 228 | RomFSBuildContext::RomFSBuildContext(VirtualDir base_, VirtualDir ext_) |
| 229 | : base(std::move(base_)), ext(std::move(ext_)) { | ||
| 226 | root = std::make_shared<RomFSBuildDirectoryContext>(); | 230 | root = std::make_shared<RomFSBuildDirectoryContext>(); |
| 227 | root->path = "\0"; | 231 | root->path = "\0"; |
| 228 | directories.emplace(root->path, root); | 232 | directories.emplace(root->path, root); |
| 229 | num_dirs = 1; | 233 | num_dirs = 1; |
| 230 | dir_table_size = 0x18; | 234 | dir_table_size = 0x18; |
| 231 | 235 | ||
| 232 | VisitDirectory(base, root); | 236 | VisitDirectory(base, ext, root); |
| 233 | } | 237 | } |
| 234 | 238 | ||
| 235 | RomFSBuildContext::~RomFSBuildContext() = default; | 239 | RomFSBuildContext::~RomFSBuildContext() = default; |
diff --git a/src/core/file_sys/fsmitm_romfsbuild.h b/src/core/file_sys/fsmitm_romfsbuild.h index b0c3c123b..3d377b0af 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.h +++ b/src/core/file_sys/fsmitm_romfsbuild.h | |||
| @@ -40,7 +40,7 @@ struct RomFSFileEntry; | |||
| 40 | 40 | ||
| 41 | class RomFSBuildContext { | 41 | class RomFSBuildContext { |
| 42 | public: | 42 | public: |
| 43 | explicit RomFSBuildContext(VirtualDir base); | 43 | explicit RomFSBuildContext(VirtualDir base, VirtualDir ext = nullptr); |
| 44 | ~RomFSBuildContext(); | 44 | ~RomFSBuildContext(); |
| 45 | 45 | ||
| 46 | // This finalizes the context. | 46 | // This finalizes the context. |
| @@ -48,6 +48,7 @@ public: | |||
| 48 | 48 | ||
| 49 | private: | 49 | private: |
| 50 | VirtualDir base; | 50 | VirtualDir base; |
| 51 | VirtualDir ext; | ||
| 51 | std::shared_ptr<RomFSBuildDirectoryContext> root; | 52 | std::shared_ptr<RomFSBuildDirectoryContext> root; |
| 52 | std::map<std::string, std::shared_ptr<RomFSBuildDirectoryContext>, std::less<>> directories; | 53 | std::map<std::string, std::shared_ptr<RomFSBuildDirectoryContext>, std::less<>> directories; |
| 53 | std::map<std::string, std::shared_ptr<RomFSBuildFileContext>, std::less<>> files; | 54 | std::map<std::string, std::shared_ptr<RomFSBuildFileContext>, std::less<>> files; |
| @@ -59,7 +60,8 @@ private: | |||
| 59 | u64 file_hash_table_size = 0; | 60 | u64 file_hash_table_size = 0; |
| 60 | u64 file_partition_size = 0; | 61 | u64 file_partition_size = 0; |
| 61 | 62 | ||
| 62 | void VisitDirectory(VirtualDir filesys, std::shared_ptr<RomFSBuildDirectoryContext> parent); | 63 | void VisitDirectory(VirtualDir filesys, VirtualDir ext, |
| 64 | std::shared_ptr<RomFSBuildDirectoryContext> parent); | ||
| 63 | 65 | ||
| 64 | bool AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, | 66 | bool AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, |
| 65 | std::shared_ptr<RomFSBuildDirectoryContext> dir_ctx); | 67 | std::shared_ptr<RomFSBuildDirectoryContext> dir_ctx); |
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 539698f6e..76b51fe56 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -162,11 +162,17 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t | |||
| 162 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | 162 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); |
| 163 | 163 | ||
| 164 | std::vector<VirtualDir> layers; | 164 | std::vector<VirtualDir> layers; |
| 165 | std::vector<VirtualDir> layers_ext; | ||
| 165 | layers.reserve(patch_dirs.size() + 1); | 166 | layers.reserve(patch_dirs.size() + 1); |
| 167 | layers_ext.reserve(patch_dirs.size() + 1); | ||
| 166 | for (const auto& subdir : patch_dirs) { | 168 | for (const auto& subdir : patch_dirs) { |
| 167 | auto romfs_dir = subdir->GetSubdirectory("romfs"); | 169 | auto romfs_dir = subdir->GetSubdirectory("romfs"); |
| 168 | if (romfs_dir != nullptr) | 170 | if (romfs_dir != nullptr) |
| 169 | layers.push_back(std::move(romfs_dir)); | 171 | layers.push_back(std::move(romfs_dir)); |
| 172 | |||
| 173 | auto ext_dir = subdir->GetSubdirectory("romfs_ext"); | ||
| 174 | if (ext_dir != nullptr) | ||
| 175 | layers.push_back(std::move(ext_dir)); | ||
| 170 | } | 176 | } |
| 171 | layers.push_back(std::move(extracted)); | 177 | layers.push_back(std::move(extracted)); |
| 172 | 178 | ||
| @@ -175,7 +181,12 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t | |||
| 175 | return; | 181 | return; |
| 176 | } | 182 | } |
| 177 | 183 | ||
| 178 | auto packed = CreateRomFS(std::move(layered)); | 184 | auto layered_ext = LayeredVfsDirectory::MakeLayeredDirectory(std::move(layers_ext)); |
| 185 | if (layered_ext == nullptr) { | ||
| 186 | return; | ||
| 187 | } | ||
| 188 | |||
| 189 | auto packed = CreateRomFS(std::move(layered), std::move(layered_ext)); | ||
| 179 | if (packed == nullptr) { | 190 | if (packed == nullptr) { |
| 180 | return; | 191 | return; |
| 181 | } | 192 | } |
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp index 5910f7046..81e1f66ac 100644 --- a/src/core/file_sys/romfs.cpp +++ b/src/core/file_sys/romfs.cpp | |||
| @@ -129,11 +129,11 @@ VirtualDir ExtractRomFS(VirtualFile file, RomFSExtractionType type) { | |||
| 129 | return out; | 129 | return out; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | VirtualFile CreateRomFS(VirtualDir dir) { | 132 | VirtualFile CreateRomFS(VirtualDir dir, VirtualDir ext) { |
| 133 | if (dir == nullptr) | 133 | if (dir == nullptr) |
| 134 | return nullptr; | 134 | return nullptr; |
| 135 | 135 | ||
| 136 | RomFSBuildContext ctx{dir}; | 136 | RomFSBuildContext ctx{dir, ext}; |
| 137 | return ConcatenatedVfsFile::MakeConcatenatedFile(0, ctx.Build(), dir->GetName()); | 137 | return ConcatenatedVfsFile::MakeConcatenatedFile(0, ctx.Build(), dir->GetName()); |
| 138 | } | 138 | } |
| 139 | 139 | ||
diff --git a/src/core/file_sys/romfs.h b/src/core/file_sys/romfs.h index ecd1eb725..0ec404731 100644 --- a/src/core/file_sys/romfs.h +++ b/src/core/file_sys/romfs.h | |||
| @@ -44,6 +44,6 @@ VirtualDir ExtractRomFS(VirtualFile file, | |||
| 44 | 44 | ||
| 45 | // Converts a VFS filesystem into a RomFS binary | 45 | // Converts a VFS filesystem into a RomFS binary |
| 46 | // Returns nullptr on failure | 46 | // Returns nullptr on failure |
| 47 | VirtualFile CreateRomFS(VirtualDir dir); | 47 | VirtualFile CreateRomFS(VirtualDir dir, VirtualDir ext = nullptr); |
| 48 | 48 | ||
| 49 | } // namespace FileSys | 49 | } // namespace FileSys |