mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Core/DiscIO: Add a setting to load the running game into memory via CachedBlobReader.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "DiscIO/Volume.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -16,8 +16,11 @@
|
||||
#include "Common/Crypto/SHA1.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/IOS/ES/Formats.h"
|
||||
|
||||
#include "DiscIO/Blob.h"
|
||||
#include "DiscIO/CachedBlob.h"
|
||||
#include "DiscIO/DiscUtils.h"
|
||||
#include "DiscIO/Enums.h"
|
||||
#include "DiscIO/VolumeDisc.h"
|
||||
@@ -84,16 +87,21 @@ std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t>
|
||||
return names;
|
||||
}
|
||||
|
||||
static std::unique_ptr<VolumeDisc> TryCreateDisc(std::unique_ptr<BlobReader>& reader)
|
||||
template <typename T = std::identity>
|
||||
static std::unique_ptr<VolumeDisc> TryCreateDisc(std::unique_ptr<BlobReader> reader,
|
||||
const T& reader_adapter_factory = {})
|
||||
{
|
||||
if (!reader)
|
||||
return nullptr;
|
||||
|
||||
// `reader_adapter_factory` is used *after* successful magic word read.
|
||||
// This prevents `CachedBlobReader` from showing warnings when failing to scrub a .dol file.
|
||||
|
||||
if (reader->ReadSwapped<u32>(0x18) == WII_DISC_MAGIC)
|
||||
return std::make_unique<VolumeWii>(std::move(reader));
|
||||
return std::make_unique<VolumeWii>(reader_adapter_factory(std::move(reader)));
|
||||
|
||||
if (reader->ReadSwapped<u32>(0x1C) == GAMECUBE_DISC_MAGIC)
|
||||
return std::make_unique<VolumeGC>(std::move(reader));
|
||||
return std::make_unique<VolumeGC>(reader_adapter_factory(std::move(reader)));
|
||||
|
||||
// No known magic words found
|
||||
return nullptr;
|
||||
@@ -101,7 +109,7 @@ static std::unique_ptr<VolumeDisc> TryCreateDisc(std::unique_ptr<BlobReader>& re
|
||||
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(std::unique_ptr<BlobReader> reader)
|
||||
{
|
||||
return TryCreateDisc(reader);
|
||||
return TryCreateDisc(std::move(reader));
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path)
|
||||
@@ -109,7 +117,15 @@ std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path)
|
||||
return CreateDisc(CreateBlobReader(path));
|
||||
}
|
||||
|
||||
static std::unique_ptr<VolumeWAD> TryCreateWAD(std::unique_ptr<BlobReader>& reader)
|
||||
std::unique_ptr<VolumeDisc> CreateDiscForCore(const std::string& path)
|
||||
{
|
||||
if (Config::Get(Config::MAIN_LOAD_GAME_INTO_MEMORY))
|
||||
return TryCreateDisc(CreateBlobReader(path), CreateScrubbingCachedBlobReader);
|
||||
|
||||
return CreateDisc(path);
|
||||
}
|
||||
|
||||
static std::unique_ptr<VolumeWAD> TryCreateWAD(std::unique_ptr<BlobReader> reader)
|
||||
{
|
||||
if (!reader)
|
||||
return nullptr;
|
||||
@@ -126,7 +142,7 @@ static std::unique_ptr<VolumeWAD> TryCreateWAD(std::unique_ptr<BlobReader>& read
|
||||
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(std::unique_ptr<BlobReader> reader)
|
||||
{
|
||||
return TryCreateWAD(reader);
|
||||
return TryCreateWAD(std::move(reader));
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path)
|
||||
@@ -136,11 +152,11 @@ std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path)
|
||||
|
||||
std::unique_ptr<Volume> CreateVolume(std::unique_ptr<BlobReader> reader)
|
||||
{
|
||||
std::unique_ptr<VolumeDisc> disc = TryCreateDisc(reader);
|
||||
std::unique_ptr<VolumeDisc> disc = TryCreateDisc(std::move(reader));
|
||||
if (disc)
|
||||
return disc;
|
||||
|
||||
std::unique_ptr<VolumeWAD> wad = TryCreateWAD(reader);
|
||||
std::unique_ptr<VolumeWAD> wad = TryCreateWAD(std::move(reader));
|
||||
if (wad)
|
||||
return wad;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user