summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO
diff options
context:
space:
mode:
authorLinktothepast <kostamarino@gmail.com>2015-09-28 16:50:35 +0300
committerLinktothepast <kostamarino@gmail.com>2015-09-28 16:50:35 +0300
commit748be565b8df535ef558e74b38cd0f4d615f8a21 (patch)
treeb151efee0a87e99125f2401325a9bddecf84fc73 /Source/Core/DiscIO
parentcf17fccdd3093a1b8476b10183b1c4bde36da74d (diff)
parentce493b897d6d3735c930a8465cc0c26bbe5feb86 (diff)
Merge remote-tracking branch 'dolphin-emu/master' into gameinis
Diffstat (limited to 'Source/Core/DiscIO')
-rw-r--r--Source/Core/DiscIO/Blob.cpp2
-rw-r--r--Source/Core/DiscIO/Blob.h5
-rw-r--r--Source/Core/DiscIO/CISOBlob.h1
-rw-r--r--Source/Core/DiscIO/CompressedBlob.cpp10
-rw-r--r--Source/Core/DiscIO/CompressedBlob.h5
-rw-r--r--Source/Core/DiscIO/DiscIO.vcxproj4
-rw-r--r--Source/Core/DiscIO/DiscIO.vcxproj.filters5
-rw-r--r--Source/Core/DiscIO/DiscScrubber.cpp9
-rw-r--r--Source/Core/DiscIO/DriveBlob.cpp2
-rw-r--r--Source/Core/DiscIO/DriveBlob.h3
-rw-r--r--Source/Core/DiscIO/FileBlob.h1
-rw-r--r--Source/Core/DiscIO/FileSystemGCWii.cpp3
-rw-r--r--Source/Core/DiscIO/FileSystemGCWii.h21
-rw-r--r--Source/Core/DiscIO/NANDContentLoader.cpp1
-rw-r--r--Source/Core/DiscIO/Volume.h8
-rw-r--r--Source/Core/DiscIO/VolumeCommon.cpp7
-rw-r--r--Source/Core/DiscIO/VolumeCreator.cpp58
-rw-r--r--Source/Core/DiscIO/VolumeCreator.h3
-rw-r--r--Source/Core/DiscIO/VolumeDirectory.cpp13
-rw-r--r--Source/Core/DiscIO/VolumeDirectory.h3
-rw-r--r--Source/Core/DiscIO/VolumeGC.cpp19
-rw-r--r--Source/Core/DiscIO/VolumeGC.h7
-rw-r--r--Source/Core/DiscIO/VolumeWad.cpp18
-rw-r--r--Source/Core/DiscIO/VolumeWad.h9
-rw-r--r--Source/Core/DiscIO/VolumeWiiCrypted.cpp25
-rw-r--r--Source/Core/DiscIO/VolumeWiiCrypted.h9
-rw-r--r--Source/Core/DiscIO/WbfsBlob.cpp9
-rw-r--r--Source/Core/DiscIO/WbfsBlob.h1
-rw-r--r--Source/Core/DiscIO/WiiWad.cpp1
29 files changed, 159 insertions, 103 deletions
diff --git a/Source/Core/DiscIO/Blob.cpp b/Source/Core/DiscIO/Blob.cpp
index 19cb36d8b3..9ed8577c38 100644
--- a/Source/Core/DiscIO/Blob.cpp
+++ b/Source/Core/DiscIO/Blob.cpp
@@ -129,7 +129,7 @@ IBlobReader* CreateBlobReader(const std::string& filename)
if (IsWbfsBlob(filename))
return WbfsFileReader::Create(filename);
- if (IsCompressedBlob(filename))
+ if (IsGCZBlob(filename))
return CompressedBlobReader::Create(filename);
if (IsCISOBlob(filename))
diff --git a/Source/Core/DiscIO/Blob.h b/Source/Core/DiscIO/Blob.h
index 54ef5580c2..a20ba1888a 100644
--- a/Source/Core/DiscIO/Blob.h
+++ b/Source/Core/DiscIO/Blob.h
@@ -25,7 +25,8 @@ class IBlobReader
public:
virtual ~IBlobReader() {}
- virtual u64 GetRawSize() const = 0;
+ virtual bool IsCompressed() const = 0;
+ virtual u64 GetRawSize() const = 0;
virtual u64 GetDataSize() const = 0;
// NOT thread-safe - can't call this from multiple threads.
virtual bool Read(u64 offset, u64 size, u8* out_ptr) = 0;
@@ -46,7 +47,7 @@ public:
// A pointer returned by GetBlockData is invalidated as soon as GetBlockData, Read, or ReadMultipleAlignedBlocks is called again.
const u8 *GetBlockData(u64 block_num);
- virtual bool Read(u64 offset, u64 size, u8 *out_ptr) override;
+ bool Read(u64 offset, u64 size, u8 *out_ptr) override;
friend class DriveReader;
protected:
diff --git a/Source/Core/DiscIO/CISOBlob.h b/Source/Core/DiscIO/CISOBlob.h
index 7a4638ecd7..2cbf78ba62 100644
--- a/Source/Core/DiscIO/CISOBlob.h
+++ b/Source/Core/DiscIO/CISOBlob.h
@@ -36,6 +36,7 @@ class CISOFileReader : public IBlobReader
public:
static CISOFileReader* Create(const std::string& filename);
+ bool IsCompressed() const override { return true; }
u64 GetDataSize() const override;
u64 GetRawSize() const override;
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp
index 04304b7613..7b01aeed5d 100644
--- a/Source/Core/DiscIO/CompressedBlob.cpp
+++ b/Source/Core/DiscIO/CompressedBlob.cpp
@@ -19,7 +19,9 @@
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/Hash.h"
+#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
+#include "Common/Logging/Log.h"
#include "DiscIO/Blob.h"
#include "DiscIO/CompressedBlob.h"
#include "DiscIO/DiscScrubber.h"
@@ -55,7 +57,7 @@ CompressedBlobReader::CompressedBlobReader(const std::string& filename) : m_file
CompressedBlobReader* CompressedBlobReader::Create(const std::string& filename)
{
- if (IsCompressedBlob(filename))
+ if (IsGCZBlob(filename))
return new CompressedBlobReader(filename);
else
return nullptr;
@@ -148,7 +150,7 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
{
bool scrubbing = false;
- if (IsCompressedBlob(infile))
+ if (IsGCZBlob(infile))
{
PanicAlertT("\"%s\" is already compressed! Cannot compress it further.", infile.c_str());
return false;
@@ -330,7 +332,7 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, CompressCB callback, void* arg)
{
- if (!IsCompressedBlob(infile))
+ if (!IsGCZBlob(infile))
{
PanicAlertT("File not compressed");
return false;
@@ -400,7 +402,7 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile,
return true;
}
-bool IsCompressedBlob(const std::string& filename)
+bool IsGCZBlob(const std::string& filename)
{
File::IOFile f(filename, "rb");
diff --git a/Source/Core/DiscIO/CompressedBlob.h b/Source/Core/DiscIO/CompressedBlob.h
index 7157f805b3..d319ab3927 100644
--- a/Source/Core/DiscIO/CompressedBlob.h
+++ b/Source/Core/DiscIO/CompressedBlob.h
@@ -23,11 +23,11 @@
namespace DiscIO
{
-bool IsCompressedBlob(const std::string& filename);
+bool IsGCZBlob(const std::string& filename);
const u32 kBlobCookie = 0xB10BC001;
-// A blob file structure:
+// GCZ file structure:
// BlobHeader
// u64 offsetsToBlocks[n], top bit specifies whether the block is compressed, or not.
// compressed data
@@ -49,6 +49,7 @@ public:
static CompressedBlobReader* Create(const std::string& filename);
~CompressedBlobReader();
const CompressedBlobHeader &GetHeader() const { return m_header; }
+ bool IsCompressed() const override { return true; }
u64 GetDataSize() const override { return m_header.data_size; }
u64 GetRawSize() const override { return m_file_size; }
u64 GetBlockCompressedSize(u64 block_num) const;
diff --git a/Source/Core/DiscIO/DiscIO.vcxproj b/Source/Core/DiscIO/DiscIO.vcxproj
index b0a9ef63fd..3250c37531 100644
--- a/Source/Core/DiscIO/DiscIO.vcxproj
+++ b/Source/Core/DiscIO/DiscIO.vcxproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
@@ -16,7 +16,7 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
diff --git a/Source/Core/DiscIO/DiscIO.vcxproj.filters b/Source/Core/DiscIO/DiscIO.vcxproj.filters
index 3d27813cba..68bde38f73 100644
--- a/Source/Core/DiscIO/DiscIO.vcxproj.filters
+++ b/Source/Core/DiscIO/DiscIO.vcxproj.filters
@@ -1,12 +1,9 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="DiscScrubber">
<UniqueIdentifier>{3873659a-9a30-4a58-af9e-8dad7d7eb627}</UniqueIdentifier>
</Filter>
- <Filter Include="FileHandler">
- <UniqueIdentifier>{324d4b72-d25b-4c83-bd61-6c9e85e59895}</UniqueIdentifier>
- </Filter>
<Filter Include="FileSystem">
<UniqueIdentifier>{bd7dbc22-b233-4f82-a369-034f04133b73}</UniqueIdentifier>
</Filter>
diff --git a/Source/Core/DiscIO/DiscScrubber.cpp b/Source/Core/DiscIO/DiscScrubber.cpp
index e44195492b..e669a5f4b3 100644
--- a/Source/Core/DiscIO/DiscScrubber.cpp
+++ b/Source/Core/DiscIO/DiscScrubber.cpp
@@ -12,6 +12,7 @@
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
+#include "Common/Logging/Log.h"
#include "DiscIO/DiscScrubber.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
@@ -265,8 +266,14 @@ bool ParsePartitionData(SPartition& _rPartition)
// Ready some stuff
m_Disc = CreateVolumeFromFilename(m_Filename, _rPartition.GroupNumber, _rPartition.Number);
- std::unique_ptr<IFileSystem> filesystem(CreateFileSystem(m_Disc));
+ if (m_Disc == nullptr)
+ {
+ ERROR_LOG(DISCIO, "Failed to create volume from file %s", m_Filename.c_str());
+ m_Disc = OldVolume;
+ return false;
+ }
+ std::unique_ptr<IFileSystem> filesystem(CreateFileSystem(m_Disc));
if (!filesystem)
{
ERROR_LOG(DISCIO, "Failed to create filesystem for group %d partition %u", _rPartition.GroupNumber, _rPartition.Number);
diff --git a/Source/Core/DiscIO/DriveBlob.cpp b/Source/Core/DiscIO/DriveBlob.cpp
index 3f0b073945..07105a9170 100644
--- a/Source/Core/DiscIO/DriveBlob.cpp
+++ b/Source/Core/DiscIO/DriveBlob.cpp
@@ -8,6 +8,8 @@
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
+#include "Common/MsgHandler.h"
+#include "Common/Logging/Log.h"
#include "DiscIO/Blob.h"
#include "DiscIO/DriveBlob.h"
diff --git a/Source/Core/DiscIO/DriveBlob.h b/Source/Core/DiscIO/DriveBlob.h
index 2c46e5b225..0ae09f5089 100644
--- a/Source/Core/DiscIO/DriveBlob.h
+++ b/Source/Core/DiscIO/DriveBlob.h
@@ -23,10 +23,11 @@ class DriveReader : public SectorReader
public:
static DriveReader* Create(const std::string& drive);
~DriveReader();
+ bool IsCompressed() const override { return false; }
u64 GetDataSize() const override { return m_size; }
u64 GetRawSize() const override { return m_size; }
- virtual bool ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *out_ptr) override;
+ bool ReadMultipleAlignedBlocks(u64 block_num, u64 num_blocks, u8 *out_ptr) override;
private:
DriveReader(const std::string& drive);
diff --git a/Source/Core/DiscIO/FileBlob.h b/Source/Core/DiscIO/FileBlob.h
index 92135de2af..9d5aa630fa 100644
--- a/Source/Core/DiscIO/FileBlob.h
+++ b/Source/Core/DiscIO/FileBlob.h
@@ -19,6 +19,7 @@ class PlainFileReader : public IBlobReader
public:
static PlainFileReader* Create(const std::string& filename);
+ bool IsCompressed() const override { return false; }
u64 GetDataSize() const override { return m_size; }
u64 GetRawSize() const override { return m_size; }
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp
index cd6f815629..439a80af99 100644
--- a/Source/Core/DiscIO/FileSystemGCWii.cpp
+++ b/Source/Core/DiscIO/FileSystemGCWii.cpp
@@ -11,8 +11,9 @@
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
+#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
-
+#include "Common/Logging/Log.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/FileSystemGCWii.h"
#include "DiscIO/Volume.h"
diff --git a/Source/Core/DiscIO/FileSystemGCWii.h b/Source/Core/DiscIO/FileSystemGCWii.h
index 0112b695ef..f244b1a60f 100644
--- a/Source/Core/DiscIO/FileSystemGCWii.h
+++ b/Source/Core/DiscIO/FileSystemGCWii.h
@@ -21,16 +21,17 @@ class CFileSystemGCWii : public IFileSystem
public:
CFileSystemGCWii(const IVolume* _rVolume);
virtual ~CFileSystemGCWii();
- virtual bool IsValid() const override { return m_Valid; }
- virtual u64 GetFileSize(const std::string& _rFullPath) override;
- virtual const std::vector<SFileInfo>& GetFileList() override;
- virtual const std::string GetFileName(u64 _Address) override;
- virtual u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile) override;
- virtual bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override;
- virtual bool ExportApploader(const std::string& _rExportFolder) const override;
- virtual bool ExportDOL(const std::string& _rExportFolder) const override;
- virtual bool GetBootDOL(u8* &buffer, u32 DolSize) const override;
- virtual u32 GetBootDOLSize() const override;
+
+ bool IsValid() const override { return m_Valid; }
+ u64 GetFileSize(const std::string& _rFullPath) override;
+ const std::vector<SFileInfo>& GetFileList() override;
+ const std::string GetFileName(u64 _Address) override;
+ u64 ReadFile(const std::string& _rFullPath, u8* _pBuffer, u64 _MaxBufferSize, u64 _OffsetInFile) override;
+ bool ExportFile(const std::string& _rFullPath, const std::string&_rExportFilename) override;
+ bool ExportApploader(const std::string& _rExportFolder) const override;
+ bool ExportDOL(const std::string& _rExportFolder) const override;
+ bool GetBootDOL(u8* &buffer, u32 DolSize) const override;
+ u32 GetBootDOLSize() const override;
private:
bool m_Initialized;
diff --git a/Source/Core/DiscIO/NANDContentLoader.cpp b/Source/Core/DiscIO/NANDContentLoader.cpp
index c59bc8079e..733f0735d8 100644
--- a/Source/Core/DiscIO/NANDContentLoader.cpp
+++ b/Source/Core/DiscIO/NANDContentLoader.cpp
@@ -15,6 +15,7 @@
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/MathUtil.h"
+#include "Common/MsgHandler.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
#include "Common/Logging/Log.h"
diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h
index 294cf94c01..c8172c677e 100644
--- a/Source/Core/DiscIO/Volume.h
+++ b/Source/Core/DiscIO/Volume.h
@@ -24,6 +24,7 @@ public:
GAMECUBE_DISC = 0,
WII_DISC,
WII_WAD,
+ ELF_DOL,
NUMBER_OF_PLATFORMS
};
@@ -75,7 +76,7 @@ public:
return Common::swap32(temp);
}
- virtual bool GetTitleID(u8*) const { return false; }
+ virtual bool GetTitleID(u64*) const { return false; }
virtual std::unique_ptr<u8[]> GetTMD(u32 *_sz) const
{
*_sz = 0;
@@ -89,7 +90,7 @@ public:
virtual std::map<ELanguage, std::string> GetDescriptions() const { return std::map<ELanguage, std::string>(); }
virtual std::string GetCompany() const { return std::string(); }
virtual std::vector<u32> GetBanner(int* width, int* height) const;
- virtual u32 GetFSTSize() const = 0;
+ virtual u64 GetFSTSize() const = 0;
virtual std::string GetApploaderDate() const = 0;
// 0 is the first disc, 1 is the second disc
virtual u8 GetDiscNumber() const { return 0; }
@@ -100,8 +101,9 @@ public:
virtual bool ChangePartition(u64 offset) { return false; }
virtual ECountry GetCountry() const = 0;
+ virtual bool IsCompressed() const = 0;
+ // Size of virtual disc (not always accurate)
virtual u64 GetSize() const = 0;
-
// Size on disc (compressed size)
virtual u64 GetRawSize() const = 0;
diff --git a/Source/Core/DiscIO/VolumeCommon.cpp b/Source/Core/DiscIO/VolumeCommon.cpp
index f5ceac8b0f..345ead0193 100644
--- a/Source/Core/DiscIO/VolumeCommon.cpp
+++ b/Source/Core/DiscIO/VolumeCommon.cpp
@@ -29,12 +29,11 @@ std::vector<u32> IVolume::GetBanner(int* width, int* height) const
*width = 0;
*height = 0;
- u64 TitleID = 0;
- GetTitleID((u8*)&TitleID);
- TitleID = Common::swap64(TitleID);
+ u64 title_id = 0;
+ GetTitleID(&title_id);
std::string file_name = StringFromFormat("%s/title/%08x/%08x/data/banner.bin",
- File::GetUserPath(D_WIIROOT_IDX).c_str(), (u32)(TitleID >> 32), (u32)TitleID);
+ File::GetUserPath(D_WIIROOT_IDX).c_str(), (u32)(title_id >> 32), (u32)title_id);
if (!File::Exists(file_name))
return std::vector<u32>();
diff --git a/Source/Core/DiscIO/VolumeCreator.cpp b/Source/Core/DiscIO/VolumeCreator.cpp
index 14ba411d90..4b3e90e2d0 100644
--- a/Source/Core/DiscIO/VolumeCreator.cpp
+++ b/Source/Core/DiscIO/VolumeCreator.cpp
@@ -4,14 +4,16 @@
#include <cstddef>
#include <cstring>
+#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include <polarssl/aes.h>
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
-
+#include "Common/Logging/Log.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeCreator.h"
@@ -69,35 +71,26 @@ static const unsigned char s_master_key_korean[16] = {
0x13,0xf2,0xfe,0xfb,0xba,0x4c,0x9b,0x7e
};
-static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum);
+static IVolume* CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum);
EDiscType GetDiscType(IBlobReader& _rReader);
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup, u32 _VolumeNum)
{
- IBlobReader* pReader = CreateBlobReader(_rFilename);
- if (pReader == nullptr)
+ std::unique_ptr<IBlobReader> reader(CreateBlobReader(_rFilename));
+ if (reader == nullptr)
return nullptr;
- switch (GetDiscType(*pReader))
+ switch (GetDiscType(*reader))
{
case DISC_TYPE_WII:
case DISC_TYPE_GC:
- return new CVolumeGC(pReader);
+ return new CVolumeGC(std::move(reader));
case DISC_TYPE_WAD:
- return new CVolumeWAD(pReader);
+ return new CVolumeWAD(std::move(reader));
case DISC_TYPE_WII_CONTAINER:
- {
- IVolume* pVolume = CreateVolumeFromCryptedWiiImage(*pReader, _PartitionGroup, 0, _VolumeNum);
-
- if (pVolume == nullptr)
- {
- delete pReader;
- }
-
- return pVolume;
- }
+ return CreateVolumeFromCryptedWiiImage(std::move(reader), _PartitionGroup, 0, _VolumeNum);
case DISC_TYPE_UNK:
default:
@@ -106,7 +99,6 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionG
Filename += ext;
NOTICE_LOG(DISCIO, "%s does not have the Magic word for a gcm, wiidisc or wad file\n"
"Set Log Verbosity to Warning and attempt to load the game again to view the values", Filename.c_str());
- delete pReader;
}
return nullptr;
@@ -128,7 +120,7 @@ bool IsVolumeWadFile(const IVolume *_rVolume)
return (Common::swap32(MagicWord) == 0x00204973 || Common::swap32(MagicWord) == 0x00206962);
}
-void VolumeKeyForParition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
+void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
{
CBlobBigEndianReader Reader(_rReader);
@@ -153,12 +145,12 @@ void VolumeKeyForParition(IBlobReader& _rReader, u64 offset, u8* VolumeKey)
aes_crypt_cbc(&AES_ctx, AES_DECRYPT, 16, IV, SubKey, VolumeKey);
}
-static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum)
+static IVolume* CreateVolumeFromCryptedWiiImage(std::unique_ptr<IBlobReader> reader, u32 _PartitionGroup, u32 _VolumeType, u32 _VolumeNum)
{
- CBlobBigEndianReader Reader(_rReader);
+ CBlobBigEndianReader big_endian_reader(*reader);
- u32 numPartitions = Reader.Read32(0x40000 + (_PartitionGroup * 8));
- u64 PartitionsOffset = (u64)Reader.Read32(0x40000 + (_PartitionGroup * 8) + 4) << 2;
+ u32 numPartitions = big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8));
+ u64 PartitionsOffset = (u64)big_endian_reader.Read32(0x40000 + (_PartitionGroup * 8) + 4) << 2;
// Check if we're looking for a valid partition
if ((int)_VolumeNum != -1 && _VolumeNum > numPartitions)
@@ -178,21 +170,21 @@ static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _Part
};
SPartitionGroup PartitionGroup[4];
- // read all partitions
+ // Read all partitions
for (SPartitionGroup& group : PartitionGroup)
{
for (u32 i = 0; i < numPartitions; i++)
{
SPartition Partition;
- Partition.Offset = ((u64)Reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2;
- Partition.Type = Reader.Read32(PartitionsOffset + (i * 8) + 4);
+ Partition.Offset = ((u64)big_endian_reader.Read32(PartitionsOffset + (i * 8) + 0)) << 2;
+ Partition.Type = big_endian_reader.Read32(PartitionsOffset + (i * 8) + 4);
group.PartitionsVec.push_back(Partition);
}
}
- // return the partition type specified or number
+ // Return the partition type specified or number
// types: 0 = game, 1 = firmware update, 2 = channel installer
- // some partitions on ssbb use the ascii title id of the demo VC game they hold...
+ // some partitions on SSBB use the ASCII title id of the demo VC game they hold...
for (size_t i = 0; i < PartitionGroup[_PartitionGroup].PartitionsVec.size(); i++)
{
const SPartition& rPartition = PartitionGroup[_PartitionGroup].PartitionsVec.at(i);
@@ -200,8 +192,8 @@ static IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _Part
if ((rPartition.Type == _VolumeType && (int)_VolumeNum == -1) || i == _VolumeNum)
{
u8 VolumeKey[16];
- VolumeKeyForParition(_rReader, rPartition.Offset, VolumeKey);
- return new CVolumeWiiCrypted(&_rReader, rPartition.Offset, VolumeKey);
+ VolumeKeyForPartition(*reader, rPartition.Offset, VolumeKey);
+ return new CVolumeWiiCrypted(std::move(reader), rPartition.Offset, VolumeKey);
}
}
@@ -216,18 +208,18 @@ EDiscType GetDiscType(IBlobReader& _rReader)
u32 WADMagic = Reader.Read32(0x02);
u32 GCMagic = Reader.Read32(0x1C);
- // check for Wii
+ // Check for Wii
if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic != 0)
return DISC_TYPE_WII;
if (WiiMagic == 0x5D1C9EA3 && WiiContainerMagic == 0)
return DISC_TYPE_WII_CONTAINER;
- // check for WAD
+ // Check for WAD
// 0x206962 for boot2 wads
if (WADMagic == 0x00204973 || WADMagic == 0x00206962)
return DISC_TYPE_WAD;
- // check for GC
+ // Check for GC
if (GCMagic == 0xC2339F3D)
return DISC_TYPE_GC;
diff --git a/Source/Core/DiscIO/VolumeCreator.h b/Source/Core/DiscIO/VolumeCreator.h
index f890109ede..c3173a5172 100644
--- a/Source/Core/DiscIO/VolumeCreator.h
+++ b/Source/Core/DiscIO/VolumeCreator.h
@@ -16,8 +16,7 @@ class IBlobReader;
IVolume* CreateVolumeFromFilename(const std::string& _rFilename, u32 _PartitionGroup = 0, u32 _VolumeNum = -1);
IVolume* CreateVolumeFromDirectory(const std::string& _rDirectory, bool _bIsWii, const std::string& _rApploader = "", const std::string& _rDOL = "");
-bool IsVolumeWiiDisc(const IVolume *_rVolume);
bool IsVolumeWadFile(const IVolume *_rVolume);
-void VolumeKeyForParition(IBlobReader& _rReader, u64 offset, u8* VolumeKey);
+void VolumeKeyForPartition(IBlobReader& _rReader, u64 offset, u8* VolumeKey);
} // namespace
diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp
index ee22db75ab..fd3e3d8236 100644
--- a/Source/Core/DiscIO/VolumeDirectory.cpp
+++ b/Source/Core/DiscIO/VolumeDirectory.cpp
@@ -10,10 +10,12 @@
#include <string>
#include <vector>
+#include "Common/Assert.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/MathUtil.h"
+#include "Common/Logging/Log.h"
#include "DiscIO/FileBlob.h"
#include "DiscIO/FileMonitor.h"
#include "DiscIO/Volume.h"
@@ -210,7 +212,7 @@ void CVolumeDirectory::SetName(const std::string& name)
m_diskHeader[length + 0x20] = 0;
}
-u32 CVolumeDirectory::GetFSTSize() const
+u64 CVolumeDirectory::GetFSTSize() const
{
return 0;
}
@@ -225,6 +227,11 @@ IVolume::EPlatform CVolumeDirectory::GetVolumeType() const
return m_is_wii ? WII_DISC : GAMECUBE_DISC;
}
+bool CVolumeDirectory::IsCompressed() const
+{
+ return false;
+}
+
u64 CVolumeDirectory::GetSize() const
{
return 0;
@@ -467,10 +474,10 @@ void CVolumeDirectory::WriteEntry(const File::FSTEntry& entry, u32& fstOffset, u
// write entry to virtual disk
_dbg_assert_(DVDINTERFACE, m_virtualDisk.find(dataOffset) == m_virtualDisk.end());
- m_virtualDisk.insert(make_pair(dataOffset, entry.physicalName));
+ m_virtualDisk.emplace(dataOffset, entry.physicalName);
// 4 byte aligned
- dataOffset = ROUND_UP(dataOffset + entry.size, 0x8000ull);
+ dataOffset = ROUND_UP(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
}
}
diff --git a/Source/Core/DiscIO/VolumeDirectory.h b/Source/Core/DiscIO/VolumeDirectory.h
index 8053d209d2..8d90496e55 100644
--- a/Source/Core/DiscIO/VolumeDirectory.h
+++ b/Source/Core/DiscIO/VolumeDirectory.h
@@ -44,13 +44,14 @@ public:
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
void SetName(const std::string&);
- u32 GetFSTSize() const override;
+ u64 GetFSTSize() const override;
std::string GetApploaderDate() const override;
EPlatform GetVolumeType() const override;
ECountry GetCountry() const override;
+ bool IsCompressed() const override;
u64 GetSize() const override;
u64 GetRawSize() const override;
diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp
index f2e54bdde8..d1a34a5e0e 100644
--- a/Source/Core/DiscIO/VolumeGC.cpp
+++ b/Source/Core/DiscIO/VolumeGC.cpp
@@ -6,10 +6,12 @@
#include <map>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include "Common/ColorUtil.h"
#include "Common/CommonTypes.h"
+#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Common/Logging/Log.h"
#include "DiscIO/Blob.h"
@@ -20,8 +22,8 @@
namespace DiscIO
{
-CVolumeGC::CVolumeGC(IBlobReader* _pReader)
- : m_pReader(_pReader)
+CVolumeGC::CVolumeGC(std::unique_ptr<IBlobReader> reader)
+ : m_pReader(std::move(reader))
{}
CVolumeGC::~CVolumeGC()
@@ -143,7 +145,7 @@ std::vector<u32> CVolumeGC::GetBanner(int* width, int* height) const
return image_buffer;
}
-u32 CVolumeGC::GetFSTSize() const
+u64 CVolumeGC::GetFSTSize() const
{
if (m_pReader == nullptr)
return 0;
@@ -167,6 +169,11 @@ std::string CVolumeGC::GetApploaderDate() const
return DecodeString(date);
}
+bool CVolumeGC::IsCompressed() const
+{
+ return m_pReader ? m_pReader->IsCompressed() : false;
+}
+
u64 CVolumeGC::GetSize() const
{
if (m_pReader)
@@ -228,13 +235,13 @@ bool CVolumeGC::LoadBannerFile() const
else
{
m_banner_file_type = BANNER_INVALID;
- WARN_LOG(DISCIO, "Invalid opening.bnr. Type: %0x Size: %0lx", bannerSignature, (unsigned long)file_size);
+ WARN_LOG(DISCIO, "Invalid opening.bnr. Type: %0x Size: %0zx", bannerSignature, file_size);
}
}
else
{
m_banner_file_type = BANNER_INVALID;
- WARN_LOG(DISCIO, "Invalid opening.bnr. Size: %0lx", (unsigned long)file_size);
+ WARN_LOG(DISCIO, "Invalid opening.bnr. Size: %0zx", file_size);
}
return m_banner_file_type != BANNER_INVALID;
@@ -248,7 +255,7 @@ std::map<IVolume::ELanguage, std::string> CVolumeGC::ReadMultiLanguageStrings(bo
return strings;
u32 number_of_languages = 0;
- ELanguage start_language;
+ ELanguage start_language = LANGUAGE_UNKNOWN;
bool is_japanese = GetCountry() == ECountry::COUNTRY_JAPAN;
switch (m_banner_file_type)
diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h
index 35599cacf6..ed08b50871 100644
--- a/Source/Core/DiscIO/VolumeGC.h
+++ b/Source/Core/DiscIO/VolumeGC.h
@@ -22,23 +22,24 @@ class IBlobReader;
class CVolumeGC : public IVolume
{
public:
- CVolumeGC(IBlobReader* _pReader);
+ CVolumeGC(std::unique_ptr<IBlobReader> reader);
~CVolumeGC();
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override;
std::string GetUniqueID() const override;
std::string GetMakerID() const override;
u16 GetRevision() const override;
- virtual std::string GetInternalName() const override;
+ std::string GetInternalName() const override;
std::map<ELanguage, std::string> GetNames(bool prefer_long) const override;
std::map<ELanguage, std::string> GetDescriptions() const override;
std::string GetCompany() const override;
std::vector<u32> GetBanner(int* width, int* height) const override;
- u32 GetFSTSize() const override;
+ u64 GetFSTSize() const override;
std::string GetApploaderDate() const override;
u8 GetDiscNumber() const override;
EPlatform GetVolumeType() const override;
ECountry GetCountry() const override;
+ bool IsCompressed() const override;
u64 GetSize() const override;
u64 GetRawSize() const override;
diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp
index a86c944844..fb510afefc 100644
--- a/Source/Core/DiscIO/VolumeWad.cpp
+++ b/Source/Core/DiscIO/VolumeWad.cpp
@@ -4,12 +4,16 @@
#include <cstddef>
#include <map>
+#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/MathUtil.h"
+#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
+#include "Common/Logging/Log.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeWad.h"
@@ -18,8 +22,8 @@
namespace DiscIO
{
-CVolumeWAD::CVolumeWAD(IBlobReader* _pReader)
- : m_pReader(_pReader), m_offset(0), m_tmd_offset(0), m_opening_bnr_offset(0),
+CVolumeWAD::CVolumeWAD(std::unique_ptr<IBlobReader> reader)
+ : m_pReader(std::move(reader)), m_offset(0), m_tmd_offset(0), m_opening_bnr_offset(0),
m_hdr_size(0), m_cert_size(0), m_tick_size(0), m_tmd_size(0), m_data_size(0)
{
// Source: http://wiibrew.org/wiki/WAD_files
@@ -91,11 +95,12 @@ std::string CVolumeWAD::GetMakerID() const
return DecodeString(temp);
}
-bool CVolumeWAD::GetTitleID(u8* _pBuffer) const
+bool CVolumeWAD::GetTitleID(u64* buffer) const
{
- if (!Read(m_offset + 0x01DC, 8, _pBuffer))
+ if (!Read(m_offset + 0x01DC, sizeof(u64), reinterpret_cast<u8*>(buffer)))
return false;
+ *buffer = Common::swap64(*buffer);
return true;
}
@@ -121,6 +126,11 @@ std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames(bool prefer_long)
return ReadWiiNames(name_data);
}
+bool CVolumeWAD::IsCompressed() const
+{
+ return m_pReader ? m_pReader->IsCompressed() : false;
+}
+
u64 CVolumeWAD::GetSize() const
{
if (m_pReader)
diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h
index 16168aefad..99b1369fea 100644
--- a/Source/Core/DiscIO/VolumeWad.h
+++ b/Source/Core/DiscIO/VolumeWad.h
@@ -24,21 +24,22 @@ class IBlobReader;
class CVolumeWAD : public IVolume
{
public:
- CVolumeWAD(IBlobReader* _pReader);
+ CVolumeWAD(std::unique_ptr<IBlobReader> reader);
~CVolumeWAD();
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt = false) const override;
- bool GetTitleID(u8* _pBuffer) const override;
+ bool GetTitleID(u64* buffer) const override;
std::string GetUniqueID() const override;
std::string GetMakerID() const override;
u16 GetRevision() const override;
std::string GetInternalName() const override { return ""; }
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
- u32 GetFSTSize() const override { return 0; }
+ u64 GetFSTSize() const override { return 0; }
std::string GetApploaderDate() const override { return ""; }
EPlatform GetVolumeType() const override;
-
ECountry GetCountry() const override;
+
+ bool IsCompressed() const override;
u64 GetSize() const override;
u64 GetRawSize() const override;
diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp
index 5701dab1cc..87c68f8cd2 100644
--- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp
+++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp
@@ -5,7 +5,9 @@
#include <cstddef>
#include <cstring>
#include <map>
+#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include <polarssl/aes.h>
#include <polarssl/sha1.h>
@@ -25,9 +27,9 @@
namespace DiscIO
{
-CVolumeWiiCrypted::CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset,
+CVolumeWiiCrypted::CVolumeWiiCrypted(std::unique_ptr<IBlobReader> reader, u64 _VolumeOffset,
const unsigned char* _pVolumeKey)
- : m_pReader(_pReader),
+ : m_pReader(std::move(reader)),
m_AES_ctx(new aes_context),
m_pBuffer(nullptr),
m_VolumeOffset(_VolumeOffset),
@@ -44,7 +46,7 @@ bool CVolumeWiiCrypted::ChangePartition(u64 offset)
m_LastDecryptedBlockOffset = -1;
u8 volume_key[16];
- DiscIO::VolumeKeyForParition(*m_pReader, offset, volume_key);
+ DiscIO::VolumeKeyForPartition(*m_pReader, offset, volume_key);
aes_setkey_dec(m_AES_ctx.get(), volume_key, 128);
return true;
}
@@ -105,11 +107,15 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de
return true;
}
-bool CVolumeWiiCrypted::GetTitleID(u8* _pBuffer) const
+bool CVolumeWiiCrypted::GetTitleID(u64* buffer) const
{
// Tik is at m_VolumeOffset size 0x2A4
// TitleID offset in tik is 0x1DC
- return Read(m_VolumeOffset + 0x1DC, 8, _pBuffer, false);
+ if (!Read(m_VolumeOffset + 0x1DC, sizeof(u64), reinterpret_cast<u8*>(buffer), false))
+ return false;
+
+ *buffer = Common::swap64(*buffer);
+ return true;
}
std::unique_ptr<u8[]> CVolumeWiiCrypted::GetTMD(u32 *size) const
@@ -206,7 +212,7 @@ std::map<IVolume::ELanguage, std::string> CVolumeWiiCrypted::GetNames(bool prefe
return ReadWiiNames(opening_bnr);
}
-u32 CVolumeWiiCrypted::GetFSTSize() const
+u64 CVolumeWiiCrypted::GetFSTSize() const
{
if (m_pReader == nullptr)
return 0;
@@ -216,7 +222,7 @@ u32 CVolumeWiiCrypted::GetFSTSize() const
if (!Read(0x428, 0x4, (u8*)&size, true))
return 0;
- return Common::swap32(size);
+ return (u64)Common::swap32(size) << 2;
}
std::string CVolumeWiiCrypted::GetApploaderDate() const
@@ -244,6 +250,11 @@ u8 CVolumeWiiCrypted::GetDiscNumber() const
return disc_number;
}
+bool CVolumeWiiCrypted::IsCompressed() const
+{
+ return m_pReader ? m_pReader->IsCompressed() : false;
+}
+
u64 CVolumeWiiCrypted::GetSize() const
{
if (m_pReader)
diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h
index 6fd687db3d..ccf0865122 100644
--- a/Source/Core/DiscIO/VolumeWiiCrypted.h
+++ b/Source/Core/DiscIO/VolumeWiiCrypted.h
@@ -23,17 +23,17 @@ class IBlobReader;
class CVolumeWiiCrypted : public IVolume
{
public:
- CVolumeWiiCrypted(IBlobReader* _pReader, u64 _VolumeOffset, const unsigned char* _pVolumeKey);
+ CVolumeWiiCrypted(std::unique_ptr<IBlobReader> reader, u64 _VolumeOffset, const unsigned char* _pVolumeKey);
~CVolumeWiiCrypted();
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const override;
- bool GetTitleID(u8* _pBuffer) const override;
- virtual std::unique_ptr<u8[]> GetTMD(u32 *_sz) const override;
+ bool GetTitleID(u64* buffer) const override;
+ std::unique_ptr<u8[]> GetTMD(u32 *_sz) const override;
std::string GetUniqueID() const override;
std::string GetMakerID() const override;
u16 GetRevision() const override;
std::string GetInternalName() const override;
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
- u32 GetFSTSize() const override;
+ u64 GetFSTSize() const override;
std::string GetApploaderDate() const override;
u8 GetDiscNumber() const override;
@@ -43,6 +43,7 @@ public:
bool ChangePartition(u64 offset) override;
ECountry GetCountry() const override;
+ bool IsCompressed() const override;
u64 GetSize() const override;
u64 GetRawSize() const override;
diff --git a/Source/Core/DiscIO/WbfsBlob.cpp b/Source/Core/DiscIO/WbfsBlob.cpp
index ef90026621..9607f15f3c 100644
--- a/Source/Core/DiscIO/WbfsBlob.cpp
+++ b/Source/Core/DiscIO/WbfsBlob.cpp
@@ -8,8 +8,11 @@
#include <string>
#include <vector>
+#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
+#include "Common/MsgHandler.h"
+#include "Common/Logging/Log.h"
#include "DiscIO/WbfsBlob.h"
namespace DiscIO
@@ -115,8 +118,10 @@ bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
{
while (nbytes)
{
- u64 read_size = 0;
+ u64 read_size;
File::IOFile& data_file = SeekToCluster(offset, &read_size);
+ if (read_size == 0)
+ return false;
read_size = (read_size > nbytes) ? nbytes : read_size;
if (!data_file.ReadBytes(out_ptr, read_size))
@@ -160,6 +165,8 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
}
PanicAlert("Read beyond end of disc");
+ if (available)
+ *available = 0;
m_files[0]->file.Seek(0, SEEK_SET);
return m_files[0]->file;
}
diff --git a/Source/Core/DiscIO/WbfsBlob.h b/Source/Core/DiscIO/WbfsBlob.h
index f0a95b170c..75e3af449f 100644
--- a/Source/Core/DiscIO/WbfsBlob.h
+++ b/Source/Core/DiscIO/WbfsBlob.h
@@ -19,6 +19,7 @@ class WbfsFileReader : public IBlobReader
public:
static WbfsFileReader* Create(const std::string& filename);
+ bool IsCompressed() const override { return true; }
u64 GetDataSize() const override { return m_size; }
u64 GetRawSize() const override { return m_size; }
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
diff --git a/Source/Core/DiscIO/WiiWad.cpp b/Source/Core/DiscIO/WiiWad.cpp
index f6b8574983..a7ba92b2fb 100644
--- a/Source/Core/DiscIO/WiiWad.cpp
+++ b/Source/Core/DiscIO/WiiWad.cpp
@@ -7,6 +7,7 @@
#include <memory>
#include <string>
+#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/MathUtil.h"