2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-06-08 14:07:01 +00:00
|
|
|
#include <cstddef>
|
2014-08-26 03:40:05 +00:00
|
|
|
#include <memory>
|
2017-06-04 08:33:14 +00:00
|
|
|
#include <optional>
|
2017-06-08 14:07:01 +00:00
|
|
|
#include <set>
|
2013-10-18 07:32:56 +00:00
|
|
|
#include <string>
|
2017-06-08 14:37:51 +00:00
|
|
|
#include <variant>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <vector>
|
2013-10-18 07:32:56 +00:00
|
|
|
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-06-07 18:32:09 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "DiscIO/Blob.h"
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
namespace File
|
|
|
|
{
|
|
|
|
struct FSTEntry;
|
2017-06-07 18:32:09 +00:00
|
|
|
class IOFile;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2014-02-21 00:47:53 +00:00
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-06-08 14:07:01 +00:00
|
|
|
class DiscContent
|
|
|
|
{
|
|
|
|
public:
|
2017-06-08 14:37:51 +00:00
|
|
|
using ContentSource = std::variant<std::string, const u8*>;
|
|
|
|
|
2017-06-08 14:07:01 +00:00
|
|
|
DiscContent(u64 offset, u64 size, const std::string& path);
|
2017-06-08 14:37:51 +00:00
|
|
|
DiscContent(u64 offset, u64 size, const u8* data);
|
2017-06-08 14:07:01 +00:00
|
|
|
|
|
|
|
// Provided because it's convenient when searching for DiscContent in an std::set
|
|
|
|
explicit DiscContent(u64 offset);
|
|
|
|
|
|
|
|
u64 GetOffset() const;
|
|
|
|
u64 GetSize() const;
|
|
|
|
bool Read(u64* offset, u64* length, u8** buffer) const;
|
|
|
|
|
|
|
|
bool operator==(const DiscContent& other) const { return m_offset == other.m_offset; }
|
|
|
|
bool operator!=(const DiscContent& other) const { return !(*this == other); }
|
|
|
|
bool operator<(const DiscContent& other) const { return m_offset < other.m_offset; }
|
|
|
|
bool operator>(const DiscContent& other) const { return other < *this; }
|
|
|
|
bool operator<=(const DiscContent& other) const { return !(*this < other); }
|
|
|
|
bool operator>=(const DiscContent& other) const { return !(*this > other); }
|
|
|
|
private:
|
|
|
|
u64 m_offset;
|
|
|
|
u64 m_size = 0;
|
|
|
|
std::string m_path;
|
2017-06-08 14:37:51 +00:00
|
|
|
ContentSource m_content_source;
|
2017-06-08 14:07:01 +00:00
|
|
|
};
|
|
|
|
|
2017-06-07 18:32:09 +00:00
|
|
|
class DirectoryBlobReader : public BlobReader
|
2008-12-08 04:46:09 +00:00
|
|
|
{
|
2009-12-10 09:16:10 +00:00
|
|
|
public:
|
2017-06-07 18:32:09 +00:00
|
|
|
static bool IsValidDirectoryBlob(const std::string& dol_path);
|
|
|
|
static std::unique_ptr<DirectoryBlobReader> Create(File::IOFile dol, const std::string& dol_path);
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-06-08 14:37:51 +00:00
|
|
|
// We do not allow copying, because it might mess up the pointers inside DiscContents
|
|
|
|
DirectoryBlobReader(const DirectoryBlobReader&) = delete;
|
|
|
|
DirectoryBlobReader& operator=(const DirectoryBlobReader&) = delete;
|
|
|
|
DirectoryBlobReader(DirectoryBlobReader&&) = default;
|
|
|
|
DirectoryBlobReader& operator=(DirectoryBlobReader&&) = default;
|
|
|
|
|
2017-06-07 18:32:09 +00:00
|
|
|
bool Read(u64 offset, u64 length, u8* buffer) override;
|
|
|
|
bool SupportsReadWiiDecrypted() const override;
|
|
|
|
bool ReadWiiDecrypted(u64 offset, u64 size, u8* buffer, u64 partition_offset) override;
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-06-07 18:32:09 +00:00
|
|
|
BlobType GetBlobType() const override;
|
|
|
|
u64 GetRawSize() const override;
|
|
|
|
u64 GetDataSize() const override;
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2009-12-10 09:16:10 +00:00
|
|
|
private:
|
2017-06-07 18:32:09 +00:00
|
|
|
DirectoryBlobReader(File::IOFile dol_file, const std::string& root_directory);
|
|
|
|
|
2017-06-08 16:43:52 +00:00
|
|
|
bool ReadInternal(u64 offset, u64 length, u8* buffer, const std::set<DiscContent>& contents);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
void SetDiskTypeWii();
|
|
|
|
void SetDiskTypeGC();
|
|
|
|
|
2017-06-08 12:24:43 +00:00
|
|
|
void SetGameID(const std::string& id);
|
|
|
|
void SetName(const std::string&);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-06-08 12:24:43 +00:00
|
|
|
bool SetApploader(const std::string& apploader);
|
2017-06-07 18:32:09 +00:00
|
|
|
void SetDOLAndDiskType(File::IOFile dol_file);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-06-08 12:24:43 +00:00
|
|
|
void BuildFST();
|
|
|
|
|
2016-12-26 10:45:22 +00:00
|
|
|
void PadToAddress(u64 start_address, u64* address, u64* length, u8** buffer) const;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
void Write32(u32 data, u32 offset, std::vector<u8>* const buffer);
|
|
|
|
|
|
|
|
// FST creation
|
2017-03-28 00:53:42 +00:00
|
|
|
void WriteEntryData(u32* entry_offset, u8 type, u32 name_offset, u64 data_offset, u64 length,
|
|
|
|
u32 address_shift);
|
2016-12-26 10:45:22 +00:00
|
|
|
void WriteEntryName(u32* name_offset, const std::string& name);
|
|
|
|
void WriteDirectory(const File::FSTEntry& parent_entry, u32* fst_offset, u32* name_offset,
|
|
|
|
u64* data_offset, u32 parent_entry_index);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-12-26 10:45:22 +00:00
|
|
|
std::string m_root_directory;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-06-08 14:07:01 +00:00
|
|
|
std::set<DiscContent> m_virtual_disc;
|
2017-06-08 16:43:52 +00:00
|
|
|
std::set<DiscContent> m_nonpartition_contents;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-06-07 18:32:09 +00:00
|
|
|
bool m_is_wii = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// GameCube has no shift, Wii has 2 bit shift
|
2017-06-07 18:32:09 +00:00
|
|
|
u32 m_address_shift = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// first address on disk containing file data
|
2016-12-26 10:45:22 +00:00
|
|
|
u64 m_data_start_address;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-12-26 10:45:22 +00:00
|
|
|
u64 m_fst_name_offset;
|
|
|
|
std::vector<u8> m_fst_data;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-12-26 10:45:22 +00:00
|
|
|
std::vector<u8> m_disk_header;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
2017-06-08 20:11:31 +00:00
|
|
|
struct TMDHeader
|
|
|
|
{
|
|
|
|
u32 tmd_size;
|
|
|
|
u32 tmd_offset;
|
|
|
|
} m_tmd_header;
|
|
|
|
static_assert(sizeof(TMDHeader) == 8, "Wrong size for TMDHeader");
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
struct SDiskHeaderInfo
|
|
|
|
{
|
2016-12-26 10:45:22 +00:00
|
|
|
u32 debug_monitor_size;
|
2016-06-24 08:43:46 +00:00
|
|
|
u32 simulated_mem_size;
|
|
|
|
u32 arg_offset;
|
|
|
|
u32 debug_flag;
|
|
|
|
u32 track_location;
|
|
|
|
u32 track_size;
|
|
|
|
u32 country_code;
|
|
|
|
u32 unknown;
|
|
|
|
u32 unknown2;
|
|
|
|
|
|
|
|
// All the data is byteswapped
|
|
|
|
SDiskHeaderInfo()
|
|
|
|
{
|
2016-12-26 10:45:22 +00:00
|
|
|
debug_monitor_size = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
simulated_mem_size = 0;
|
|
|
|
arg_offset = 0;
|
|
|
|
debug_flag = 0;
|
|
|
|
track_location = 0;
|
|
|
|
track_size = 0;
|
|
|
|
country_code = 0;
|
|
|
|
unknown = 0;
|
|
|
|
unknown2 = 0;
|
|
|
|
}
|
|
|
|
};
|
2017-06-08 20:11:31 +00:00
|
|
|
static_assert(sizeof(SDiskHeaderInfo) == 36, "Wrong size for SDiskHeaderInfo");
|
2016-06-24 08:43:46 +00:00
|
|
|
#pragma pack(pop)
|
2016-12-26 10:45:22 +00:00
|
|
|
std::unique_ptr<SDiskHeaderInfo> m_disk_header_info;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
std::vector<u8> m_apploader;
|
2016-12-26 10:45:22 +00:00
|
|
|
std::vector<u8> m_dol;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
u64 m_fst_address;
|
|
|
|
u64 m_dol_address;
|
2008-12-08 04:46:09 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
} // namespace
|