| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <optional> |
| 7 |
#include <span> |
| 8 |
#include <string> |
| 9 |
#include <string_view> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include "DiscIO/DirectoryBlob.h" |
| 13 |
#include "DiscIO/RiivolutionParser.h" |
| 14 |
|
| 15 |
namespace Core |
| 16 |
{ |
| 17 |
class CPUThreadGuard; |
| 18 |
} |
| 19 |
|
| 20 |
namespace DiscIO::Riivolution |
| 21 |
{ |
| 22 |
struct SavegameRedirect |
| 23 |
{ |
| 24 |
std::string m_target_path; |
| 25 |
bool m_clone; |
| 26 |
}; |
| 27 |
|
| 28 |
class FileDataLoader |
| 29 |
{ |
| 30 |
public: |
| 31 |
struct Node |
| 32 |
{ |
| 33 |
std::string m_filename; |
| 34 |
bool m_is_directory; |
| 35 |
}; |
| 36 |
|
| 37 |
virtual ~FileDataLoader(); |
| 38 |
virtual std::optional<u64> GetExternalFileSize(std::string_view external_relative_path) = 0; |
| 39 |
virtual std::vector<u8> GetFileContents(std::string_view external_relative_path) = 0; |
| 40 |
virtual std::vector<Node> GetFolderContents(std::string_view external_relative_path) = 0; |
| 41 |
virtual BuilderContentSource MakeContentSource(std::string_view external_relative_path, |
| 42 |
u64 external_offset, u64 external_size, |
| 43 |
u64 disc_offset) = 0; |
| 44 |
virtual std::optional<std::string> |
| 45 |
ResolveSavegameRedirectPath(std::string_view external_relative_path) = 0; |
| 46 |
}; |
| 47 |
|
| 48 |
class FileDataLoaderHostFS final : public FileDataLoader |
| 49 |
{ |
| 50 |
public: |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
FileDataLoaderHostFS(std::string sd_root, const std::string& xml_path, |
| 55 |
std::string_view patch_root); |
| 56 |
|
| 57 |
std::optional<u64> GetExternalFileSize(std::string_view external_relative_path) override; |
| 58 |
std::vector<u8> GetFileContents(std::string_view external_relative_path) override; |
| 59 |
std::vector<FileDataLoader::Node> |
| 60 |
GetFolderContents(std::string_view external_relative_path) override; |
| 61 |
BuilderContentSource MakeContentSource(std::string_view external_relative_path, |
| 62 |
u64 external_offset, u64 external_size, |
| 63 |
u64 disc_offset) override; |
| 64 |
std::optional<std::string> |
| 65 |
ResolveSavegameRedirectPath(std::string_view external_relative_path) override; |
| 66 |
|
| 67 |
private: |
| 68 |
std::optional<std::string> |
| 69 |
MakeAbsoluteFromRelative(std::string_view external_relative_path) const; |
| 70 |
|
| 71 |
std::string m_sd_root; |
| 72 |
std::string m_patch_root; |
| 73 |
}; |
| 74 |
|
| 75 |
enum class PatchIndex |
| 76 |
{ |
| 77 |
FileSystem, |
| 78 |
DolphinSysFiles, |
| 79 |
}; |
| 80 |
|
| 81 |
void ApplyPatchesToFiles(std::span<const Patch> patches, PatchIndex index, |
| 82 |
std::vector<FSTBuilderNode>* fst, FSTBuilderNode* dol_node); |
| 83 |
void ApplyGeneralMemoryPatches(const Core::CPUThreadGuard& guard, std::span<const Patch> patches); |
| 84 |
void ApplyApploaderMemoryPatches(const Core::CPUThreadGuard& guard, std::span<const Patch> patches, |
| 85 |
u32 ram_address, u32 ram_length); |
| 86 |
std::optional<SavegameRedirect> ExtractSavegameRedirect(std::span<const Patch> riivolution_patches); |
| 87 |
} |