diff options
| author | 2018-10-08 12:31:27 -0400 | |
|---|---|---|
| committer | 2018-10-08 12:31:27 -0400 | |
| commit | 561d79e03443aec02f54e1e43437bc1d5b90ca88 (patch) | |
| tree | 7e2e14de7eb8dea04c415e70a3b638d76084c86b /src | |
| parent | Merge pull request #1424 from DarkLordZach/ips-witch (diff) | |
| parent | patch_manager: Avoid romfs_ext requirement for patching (diff) | |
| download | yuzu-561d79e03443aec02f54e1e43437bc1d5b90ca88.tar.gz yuzu-561d79e03443aec02f54e1e43437bc1d5b90ca88.tar.xz yuzu-561d79e03443aec02f54e1e43437bc1d5b90ca88.zip | |
Merge pull request #1423 from DarkLordZach/romfs-file-exts
fsmitm_romfsbuild: Add support for stubbing and IPS patches in LFS
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/fsmitm_romfsbuild.cpp | 26 | ||||
| -rw-r--r-- | src/core/file_sys/fsmitm_romfsbuild.h | 6 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 10 | ||||
| -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, 10 deletions
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 2a913ce82..47b7526c7 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include "common/alignment.h" | 26 | #include "common/alignment.h" |
| 27 | #include "common/assert.h" | 27 | #include "common/assert.h" |
| 28 | #include "core/file_sys/fsmitm_romfsbuild.h" | 28 | #include "core/file_sys/fsmitm_romfsbuild.h" |
| 29 | #include "core/file_sys/ips_layer.h" | ||
| 29 | #include "core/file_sys/vfs.h" | 30 | #include "core/file_sys/vfs.h" |
| 30 | #include "core/file_sys/vfs_vector.h" | 31 | #include "core/file_sys/vfs_vector.h" |
| 31 | 32 | ||
| @@ -123,7 +124,7 @@ static u64 romfs_get_hash_table_count(u64 num_entries) { | |||
| 123 | return count; | 124 | return count; |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | 127 | void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext, |
| 127 | std::shared_ptr<RomFSBuildDirectoryContext> parent) { | 128 | std::shared_ptr<RomFSBuildDirectoryContext> parent) { |
| 128 | std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; | 129 | std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; |
| 129 | 130 | ||
| @@ -144,6 +145,9 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | |||
| 144 | 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()); |
| 145 | child->path = parent->path + "/" + kv.first; | 146 | child->path = parent->path + "/" + kv.first; |
| 146 | 147 | ||
| 148 | if (ext != nullptr && ext->GetFileRelative(child->path + ".stub") != nullptr) | ||
| 149 | continue; | ||
| 150 | |||
| 147 | // Sanity check on path_len | 151 | // Sanity check on path_len |
| 148 | ASSERT(child->path_len < FS_MAX_PATH); | 152 | ASSERT(child->path_len < FS_MAX_PATH); |
| 149 | 153 | ||
| @@ -157,11 +161,24 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | |||
| 157 | 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()); |
| 158 | child->path = parent->path + "/" + kv.first; | 162 | child->path = parent->path + "/" + kv.first; |
| 159 | 163 | ||
| 164 | if (ext != nullptr && ext->GetFileRelative(child->path + ".stub") != nullptr) | ||
| 165 | continue; | ||
| 166 | |||
| 160 | // Sanity check on path_len | 167 | // Sanity check on path_len |
| 161 | ASSERT(child->path_len < FS_MAX_PATH); | 168 | ASSERT(child->path_len < FS_MAX_PATH); |
| 162 | 169 | ||
| 163 | child->source = root_romfs->GetFileRelative(child->path); | 170 | child->source = root_romfs->GetFileRelative(child->path); |
| 164 | 171 | ||
| 172 | if (ext != nullptr) { | ||
| 173 | const auto ips = ext->GetFileRelative(child->path + ".ips"); | ||
| 174 | |||
| 175 | if (ips != nullptr) { | ||
| 176 | auto patched = PatchIPS(child->source, ips); | ||
| 177 | if (patched != nullptr) | ||
| 178 | child->source = std::move(patched); | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 165 | child->size = child->source->GetSize(); | 182 | child->size = child->source->GetSize(); |
| 166 | 183 | ||
| 167 | AddFile(parent, child); | 184 | AddFile(parent, child); |
| @@ -169,7 +186,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, | |||
| 169 | } | 186 | } |
| 170 | 187 | ||
| 171 | for (auto& child : child_dirs) { | 188 | for (auto& child : child_dirs) { |
| 172 | this->VisitDirectory(root_romfs, child); | 189 | this->VisitDirectory(root_romfs, ext, child); |
| 173 | } | 190 | } |
| 174 | } | 191 | } |
| 175 | 192 | ||
| @@ -208,14 +225,15 @@ bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> pare | |||
| 208 | return true; | 225 | return true; |
| 209 | } | 226 | } |
| 210 | 227 | ||
| 211 | RomFSBuildContext::RomFSBuildContext(VirtualDir base_) : base(std::move(base_)) { | 228 | RomFSBuildContext::RomFSBuildContext(VirtualDir base_, VirtualDir ext_) |
| 229 | : base(std::move(base_)), ext(std::move(ext_)) { | ||
| 212 | root = std::make_shared<RomFSBuildDirectoryContext>(); | 230 | root = std::make_shared<RomFSBuildDirectoryContext>(); |
| 213 | root->path = "\0"; | 231 | root->path = "\0"; |
| 214 | directories.emplace(root->path, root); | 232 | directories.emplace(root->path, root); |
| 215 | num_dirs = 1; | 233 | num_dirs = 1; |
| 216 | dir_table_size = 0x18; | 234 | dir_table_size = 0x18; |
| 217 | 235 | ||
| 218 | VisitDirectory(base, root); | 236 | VisitDirectory(base, ext, root); |
| 219 | } | 237 | } |
| 220 | 238 | ||
| 221 | 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 7b31a57a4..b14d7cb0a 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -182,11 +182,17 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t | |||
| 182 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | 182 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); |
| 183 | 183 | ||
| 184 | std::vector<VirtualDir> layers; | 184 | std::vector<VirtualDir> layers; |
| 185 | std::vector<VirtualDir> layers_ext; | ||
| 185 | layers.reserve(patch_dirs.size() + 1); | 186 | layers.reserve(patch_dirs.size() + 1); |
| 187 | layers_ext.reserve(patch_dirs.size() + 1); | ||
| 186 | for (const auto& subdir : patch_dirs) { | 188 | for (const auto& subdir : patch_dirs) { |
| 187 | auto romfs_dir = subdir->GetSubdirectory("romfs"); | 189 | auto romfs_dir = subdir->GetSubdirectory("romfs"); |
| 188 | if (romfs_dir != nullptr) | 190 | if (romfs_dir != nullptr) |
| 189 | layers.push_back(std::move(romfs_dir)); | 191 | layers.push_back(std::move(romfs_dir)); |
| 192 | |||
| 193 | auto ext_dir = subdir->GetSubdirectory("romfs_ext"); | ||
| 194 | if (ext_dir != nullptr) | ||
| 195 | layers_ext.push_back(std::move(ext_dir)); | ||
| 190 | } | 196 | } |
| 191 | layers.push_back(std::move(extracted)); | 197 | layers.push_back(std::move(extracted)); |
| 192 | 198 | ||
| @@ -195,7 +201,9 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t | |||
| 195 | return; | 201 | return; |
| 196 | } | 202 | } |
| 197 | 203 | ||
| 198 | auto packed = CreateRomFS(std::move(layered)); | 204 | auto layered_ext = LayeredVfsDirectory::MakeLayeredDirectory(std::move(layers_ext)); |
| 205 | |||
| 206 | auto packed = CreateRomFS(std::move(layered), std::move(layered_ext)); | ||
| 199 | if (packed == nullptr) { | 207 | if (packed == nullptr) { |
| 200 | return; | 208 | return; |
| 201 | } | 209 | } |
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 |