diff options
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 29 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.h | 6 |
2 files changed, 20 insertions, 15 deletions
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index c1dd0c6d7..90b537834 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "core/hle/service/filesystem/filesystem.h" | 22 | #include "core/hle/service/filesystem/filesystem.h" |
| 23 | #include "core/loader/loader.h" | 23 | #include "core/loader/loader.h" |
| 24 | #include "core/loader/nso.h" | 24 | #include "core/loader/nso.h" |
| 25 | #include "core/memory/cheat_engine.h" | ||
| 25 | #include "core/settings.h" | 26 | #include "core/settings.h" |
| 26 | 27 | ||
| 27 | namespace FileSys { | 28 | namespace FileSys { |
| @@ -247,9 +248,10 @@ bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const { | |||
| 247 | return !CollectPatches(patch_dirs, build_id).empty(); | 248 | return !CollectPatches(patch_dirs, build_id).empty(); |
| 248 | } | 249 | } |
| 249 | 250 | ||
| 250 | static std::optional<CheatList> ReadCheatFileFromFolder(const Core::System& system, u64 title_id, | 251 | namespace { |
| 251 | const std::array<u8, 0x20>& build_id_, | 252 | std::optional<std::vector<Memory::CheatEntry>> ReadCheatFileFromFolder( |
| 252 | const VirtualDir& base_path, bool upper) { | 253 | const Core::System& system, u64 title_id, const std::array<u8, 0x20>& build_id_, |
| 254 | const VirtualDir& base_path, bool upper) { | ||
| 253 | const auto build_id_raw = Common::HexToString(build_id_, upper); | 255 | const auto build_id_raw = Common::HexToString(build_id_, upper); |
| 254 | const auto build_id = build_id_raw.substr(0, sizeof(u64) * 2); | 256 | const auto build_id = build_id_raw.substr(0, sizeof(u64) * 2); |
| 255 | const auto file = base_path->GetFile(fmt::format("{}.txt", build_id)); | 257 | const auto file = base_path->GetFile(fmt::format("{}.txt", build_id)); |
| @@ -267,12 +269,15 @@ static std::optional<CheatList> ReadCheatFileFromFolder(const Core::System& syst | |||
| 267 | return std::nullopt; | 269 | return std::nullopt; |
| 268 | } | 270 | } |
| 269 | 271 | ||
| 270 | TextCheatParser parser; | 272 | Memory::TextCheatParser parser; |
| 271 | return parser.Parse(system, data); | 273 | return parser.Parse( |
| 274 | system, std::string_view(reinterpret_cast<const char* const>(data.data()), data.size())); | ||
| 272 | } | 275 | } |
| 273 | 276 | ||
| 274 | std::vector<CheatList> PatchManager::CreateCheatList(const Core::System& system, | 277 | } // Anonymous namespace |
| 275 | const std::array<u8, 32>& build_id_) const { | 278 | |
| 279 | std::vector<Memory::CheatEntry> PatchManager::CreateCheatList( | ||
| 280 | const Core::System& system, const std::array<u8, 32>& build_id_) const { | ||
| 276 | const auto load_dir = | 281 | const auto load_dir = |
| 277 | Core::System::GetInstance().GetFileSystemController().GetModificationLoadRoot(title_id); | 282 | Core::System::GetInstance().GetFileSystemController().GetModificationLoadRoot(title_id); |
| 278 | if (load_dir == nullptr) { | 283 | if (load_dir == nullptr) { |
| @@ -284,20 +289,20 @@ std::vector<CheatList> PatchManager::CreateCheatList(const Core::System& system, | |||
| 284 | std::sort(patch_dirs.begin(), patch_dirs.end(), | 289 | std::sort(patch_dirs.begin(), patch_dirs.end(), |
| 285 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); | 290 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); |
| 286 | 291 | ||
| 287 | std::vector<CheatList> out; | 292 | std::vector<Memory::CheatEntry> out; |
| 288 | out.reserve(patch_dirs.size()); | ||
| 289 | for (const auto& subdir : patch_dirs) { | 293 | for (const auto& subdir : patch_dirs) { |
| 290 | auto cheats_dir = subdir->GetSubdirectory("cheats"); | 294 | auto cheats_dir = subdir->GetSubdirectory("cheats"); |
| 291 | if (cheats_dir != nullptr) { | 295 | if (cheats_dir != nullptr) { |
| 292 | auto res = ReadCheatFileFromFolder(system, title_id, build_id_, cheats_dir, true); | 296 | auto res = ReadCheatFileFromFolder(system, title_id, build_id_, cheats_dir, true); |
| 293 | if (res.has_value()) { | 297 | if (res.has_value()) { |
| 294 | out.push_back(std::move(*res)); | 298 | std::copy(res->begin(), res->end(), std::back_inserter(out)); |
| 295 | continue; | 299 | continue; |
| 296 | } | 300 | } |
| 297 | 301 | ||
| 298 | res = ReadCheatFileFromFolder(system, title_id, build_id_, cheats_dir, false); | 302 | res = ReadCheatFileFromFolder(system, title_id, build_id_, cheats_dir, false); |
| 299 | if (res.has_value()) | 303 | if (res.has_value()) { |
| 300 | out.push_back(std::move(*res)); | 304 | std::copy(res->begin(), res->end(), std::back_inserter(out)); |
| 305 | } | ||
| 301 | } | 306 | } |
| 302 | } | 307 | } |
| 303 | 308 | ||
diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index a363c6577..e857e6e82 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h | |||
| @@ -8,9 +8,9 @@ | |||
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | #include <string> | 9 | #include <string> |
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "core/file_sys/cheat_engine.h" | ||
| 12 | #include "core/file_sys/nca_metadata.h" | 11 | #include "core/file_sys/nca_metadata.h" |
| 13 | #include "core/file_sys/vfs.h" | 12 | #include "core/file_sys/vfs.h" |
| 13 | #include "core/memory/dmnt_cheat_types.h" | ||
| 14 | 14 | ||
| 15 | namespace Core { | 15 | namespace Core { |
| 16 | class System; | 16 | class System; |
| @@ -51,8 +51,8 @@ public: | |||
| 51 | bool HasNSOPatch(const std::array<u8, 0x20>& build_id) const; | 51 | bool HasNSOPatch(const std::array<u8, 0x20>& build_id) const; |
| 52 | 52 | ||
| 53 | // Creates a CheatList object with all | 53 | // Creates a CheatList object with all |
| 54 | std::vector<CheatList> CreateCheatList(const Core::System& system, | 54 | std::vector<Memory::CheatEntry> CreateCheatList(const Core::System& system, |
| 55 | const std::array<u8, 0x20>& build_id) const; | 55 | const std::array<u8, 0x20>& build_id) const; |
| 56 | 56 | ||
| 57 | // Currently tracked RomFS patches: | 57 | // Currently tracked RomFS patches: |
| 58 | // - Game Updates | 58 | // - Game Updates |