2021-09-22 19:22:17 -06:00
|
|
|
// Copyright 2021 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 22:23:33 -06:00
|
|
|
#include <optional>
|
2023-12-12 10:32:42 -07:00
|
|
|
#include <span>
|
2021-09-27 22:12:45 -06:00
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
2021-09-22 19:22:17 -06:00
|
|
|
#include <vector>
|
|
|
|
|
2021-09-27 22:12:45 -06:00
|
|
|
#include "DiscIO/DirectoryBlob.h"
|
2021-09-22 19:22:17 -06:00
|
|
|
#include "DiscIO/RiivolutionParser.h"
|
|
|
|
|
2023-02-12 03:07:11 -07:00
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
class CPUThreadGuard;
|
|
|
|
}
|
|
|
|
|
2021-09-27 22:12:45 -06:00
|
|
|
namespace DiscIO::Riivolution
|
|
|
|
{
|
2021-10-02 22:23:33 -06:00
|
|
|
struct SavegameRedirect
|
|
|
|
{
|
|
|
|
std::string m_target_path;
|
|
|
|
bool m_clone;
|
|
|
|
};
|
|
|
|
|
2021-09-27 22:12:45 -06:00
|
|
|
class FileDataLoader
|
2021-09-22 19:22:17 -06:00
|
|
|
{
|
2021-09-27 22:12:45 -06:00
|
|
|
public:
|
|
|
|
struct Node
|
|
|
|
{
|
|
|
|
std::string m_filename;
|
|
|
|
bool m_is_directory;
|
|
|
|
};
|
2021-09-22 19:22:17 -06:00
|
|
|
|
2021-09-27 22:12:45 -06:00
|
|
|
virtual ~FileDataLoader();
|
|
|
|
virtual std::optional<u64> GetExternalFileSize(std::string_view external_relative_path) = 0;
|
|
|
|
virtual std::vector<u8> GetFileContents(std::string_view external_relative_path) = 0;
|
|
|
|
virtual std::vector<Node> GetFolderContents(std::string_view external_relative_path) = 0;
|
|
|
|
virtual BuilderContentSource MakeContentSource(std::string_view external_relative_path,
|
|
|
|
u64 external_offset, u64 external_size,
|
|
|
|
u64 disc_offset) = 0;
|
2021-10-02 22:23:33 -06:00
|
|
|
virtual std::optional<std::string>
|
|
|
|
ResolveSavegameRedirectPath(std::string_view external_relative_path) = 0;
|
2021-09-27 22:12:45 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileDataLoaderHostFS : public FileDataLoader
|
2021-09-22 19:22:17 -06:00
|
|
|
{
|
2021-09-27 22:12:45 -06:00
|
|
|
public:
|
|
|
|
// sd_root should be an absolute path to the folder representing our virtual SD card
|
|
|
|
// xml_path should be an absolute path to the parsed XML file
|
|
|
|
// patch_root should be the 'root' attribute given in the 'patch' or 'wiiroot' XML element
|
|
|
|
FileDataLoaderHostFS(std::string sd_root, const std::string& xml_path,
|
|
|
|
std::string_view patch_root);
|
|
|
|
|
|
|
|
std::optional<u64> GetExternalFileSize(std::string_view external_relative_path) override;
|
|
|
|
std::vector<u8> GetFileContents(std::string_view external_relative_path) override;
|
|
|
|
std::vector<FileDataLoader::Node>
|
|
|
|
GetFolderContents(std::string_view external_relative_path) override;
|
|
|
|
BuilderContentSource MakeContentSource(std::string_view external_relative_path,
|
|
|
|
u64 external_offset, u64 external_size,
|
|
|
|
u64 disc_offset) override;
|
2021-10-02 22:23:33 -06:00
|
|
|
std::optional<std::string>
|
|
|
|
ResolveSavegameRedirectPath(std::string_view external_relative_path) override;
|
2021-09-27 22:12:45 -06:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::optional<std::string> MakeAbsoluteFromRelative(std::string_view external_relative_path);
|
|
|
|
|
|
|
|
std::string m_sd_root;
|
|
|
|
std::string m_patch_root;
|
|
|
|
};
|
|
|
|
|
2022-06-08 16:25:11 -06:00
|
|
|
enum class PatchIndex
|
|
|
|
{
|
|
|
|
FileSystem,
|
|
|
|
DolphinSysFiles,
|
|
|
|
};
|
|
|
|
|
2023-12-12 10:32:42 -07:00
|
|
|
void ApplyPatchesToFiles(std::span<const Patch> patches, PatchIndex index,
|
|
|
|
std::vector<FSTBuilderNode>* fst, FSTBuilderNode* dol_node);
|
|
|
|
void ApplyGeneralMemoryPatches(const Core::CPUThreadGuard& guard, std::span<const Patch> patches);
|
|
|
|
void ApplyApploaderMemoryPatches(const Core::CPUThreadGuard& guard, std::span<const Patch> patches,
|
|
|
|
u32 ram_address, u32 ram_length);
|
|
|
|
std::optional<SavegameRedirect> ExtractSavegameRedirect(std::span<const Patch> riivolution_patches);
|
2021-09-22 19:22:17 -06:00
|
|
|
} // namespace DiscIO::Riivolution
|