DiscIO: Make variables constant
This commit is contained in:
parent
f8bf35e6f0
commit
c1271c14f1
|
@ -84,7 +84,7 @@ SectorReader::~SectorReader()
|
|||
|
||||
const SectorReader::Cache* SectorReader::FindCacheLine(u64 block_num)
|
||||
{
|
||||
auto itr =
|
||||
const auto itr =
|
||||
std::ranges::find_if(m_cache, [&](const Cache& entry) { return entry.Contains(block_num); });
|
||||
if (itr == m_cache.end())
|
||||
return nullptr;
|
||||
|
@ -112,14 +112,14 @@ SectorReader::Cache* SectorReader::GetEmptyCacheLine()
|
|||
|
||||
const SectorReader::Cache* SectorReader::GetCacheLine(u64 block_num)
|
||||
{
|
||||
if (auto entry = FindCacheLine(block_num))
|
||||
if (const auto entry = FindCacheLine(block_num))
|
||||
return entry;
|
||||
|
||||
// Cache miss. Fault in the missing entry.
|
||||
Cache* cache = GetEmptyCacheLine();
|
||||
// We only read aligned chunks, this avoids duplicate overlapping entries.
|
||||
u64 chunk_idx = block_num / m_chunk_blocks;
|
||||
u32 blocks_read = ReadChunk(cache->data.data(), chunk_idx);
|
||||
const u64 chunk_idx = block_num / m_chunk_blocks;
|
||||
const u32 blocks_read = ReadChunk(cache->data.data(), chunk_idx);
|
||||
if (!blocks_read)
|
||||
return nullptr;
|
||||
cache->Fill(chunk_idx * m_chunk_blocks, blocks_read);
|
||||
|
@ -149,9 +149,10 @@ bool SectorReader::Read(u64 offset, u64 size, u8* out_ptr)
|
|||
return false;
|
||||
|
||||
// Cache entries are aligned chunks, we may not want to read from the start
|
||||
u32 read_offset = static_cast<u32>(block - cache->block_idx) * m_block_size + position_in_block;
|
||||
u32 can_read = m_block_size * cache->num_blocks - read_offset;
|
||||
u32 was_read = static_cast<u32>(std::min<u64>(can_read, remain));
|
||||
const u32 read_offset =
|
||||
static_cast<u32>(block - cache->block_idx) * m_block_size + position_in_block;
|
||||
const u32 can_read = m_block_size * cache->num_blocks - read_offset;
|
||||
const u32 was_read = static_cast<u32>(std::min<u64>(can_read, remain));
|
||||
|
||||
std::copy_n(cache->data.begin() + read_offset, was_read, out_ptr);
|
||||
|
||||
|
@ -177,12 +178,12 @@ bool SectorReader::ReadMultipleAlignedBlocks(u64 block_num, u64 cnt_blocks, u8*
|
|||
|
||||
u32 SectorReader::ReadChunk(u8* buffer, u64 chunk_num)
|
||||
{
|
||||
u64 block_num = chunk_num * m_chunk_blocks;
|
||||
const u64 block_num = chunk_num * m_chunk_blocks;
|
||||
u32 cnt_blocks = m_chunk_blocks;
|
||||
|
||||
// If we are reading the end of a disk, there may not be enough blocks to
|
||||
// read a whole chunk. We need to clamp down in that case.
|
||||
u64 end_block = (GetDataSize() + m_block_size - 1) / m_block_size;
|
||||
const u64 end_block = (GetDataSize() + m_block_size - 1) / m_block_size;
|
||||
if (end_block)
|
||||
cnt_blocks = static_cast<u32>(std::min<u64>(m_chunk_blocks, end_block - block_num));
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ std::unique_ptr<BlobReader> CompressedBlobReader::CopyReader() const
|
|||
// IMPORTANT: Calling this function invalidates all earlier pointers gotten from this function.
|
||||
u64 CompressedBlobReader::GetBlockCompressedSize(u64 block_num) const
|
||||
{
|
||||
u64 start = m_block_pointers[block_num];
|
||||
const u64 start = m_block_pointers[block_num];
|
||||
if (block_num < m_header.num_blocks - 1)
|
||||
return m_block_pointers[block_num + 1] - start;
|
||||
else if (block_num == m_header.num_blocks - 1)
|
||||
|
@ -95,7 +95,7 @@ u64 CompressedBlobReader::GetBlockCompressedSize(u64 block_num) const
|
|||
bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr)
|
||||
{
|
||||
bool uncompressed = false;
|
||||
u32 comp_block_size = (u32)GetBlockCompressedSize(block_num);
|
||||
const u32 comp_block_size = (u32)GetBlockCompressedSize(block_num);
|
||||
u64 offset = m_block_pointers[block_num] + m_data_offset;
|
||||
|
||||
if (offset & (1ULL << 63))
|
||||
|
@ -144,8 +144,8 @@ bool CompressedBlobReader::GetBlock(u64 block_num, u8* out_ptr)
|
|||
z.next_out = out_ptr;
|
||||
z.avail_out = m_header.block_size;
|
||||
inflateInit(&z);
|
||||
int status = inflate(&z, Z_FULL_FLUSH);
|
||||
u32 uncomp_size = m_header.block_size - z.avail_out;
|
||||
const int status = inflate(&z, Z_FULL_FLUSH);
|
||||
const u32 uncomp_size = m_header.block_size - z.avail_out;
|
||||
if (status != Z_STREAM_END)
|
||||
{
|
||||
// this seem to fire wrongly from time to time
|
||||
|
@ -205,7 +205,7 @@ static ConversionResult<OutputParameters> Compress(CompressThreadState* state,
|
|||
{
|
||||
state->compressed_buffer.resize(block_size);
|
||||
|
||||
int retval = deflateReset(&state->z);
|
||||
const int retval = deflateReset(&state->z);
|
||||
state->z.next_in = parameters.data.data();
|
||||
state->z.avail_in = block_size;
|
||||
state->z.next_out = state->compressed_buffer.data();
|
||||
|
@ -315,7 +315,7 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
|
|||
u64 position = 0;
|
||||
int num_compressed = 0;
|
||||
int num_stored = 0;
|
||||
int progress_monitor = std::max<int>(1, header.num_blocks / 1000);
|
||||
const int progress_monitor = std::max<int>(1, header.num_blocks / 1000);
|
||||
|
||||
const auto compress = [&](CompressThreadState* state, CompressParameters parameters) {
|
||||
return Compress(state, std::move(parameters), block_size, &hashes, &num_stored,
|
||||
|
@ -393,7 +393,7 @@ bool IsGCZBlob(File::IOFile& file)
|
|||
if (!file.Seek(0, File::SeekOrigin::Begin))
|
||||
return false;
|
||||
CompressedBlobHeader header;
|
||||
bool is_gcz = file.ReadArray(&header, 1) && header.magic_cookie == GCZ_MAGIC;
|
||||
const bool is_gcz = file.ReadArray(&header, 1) && header.magic_cookie == GCZ_MAGIC;
|
||||
file.Seek(position, File::SeekOrigin::Begin);
|
||||
return is_gcz;
|
||||
}
|
||||
|
|
|
@ -527,7 +527,7 @@ bool DirectoryBlobReader::EncryptPartitionData(u64 offset, u64 size, u8* buffer,
|
|||
u64 partition_data_offset,
|
||||
u64 partition_data_decrypted_size)
|
||||
{
|
||||
auto it = m_partitions.find(partition_data_offset);
|
||||
const auto it = m_partitions.find(partition_data_offset);
|
||||
if (it == m_partitions.end())
|
||||
return false;
|
||||
|
||||
|
@ -792,7 +792,7 @@ void DirectoryBlobReader::SetPartitionHeader(DirectoryBlobPartition* partition,
|
|||
std::vector<u8> ticket_buffer(ticket_size);
|
||||
m_nonpartition_contents.Read(partition_address + WII_PARTITION_TICKET_ADDRESS, ticket_size,
|
||||
ticket_buffer.data(), this);
|
||||
IOS::ES::TicketReader ticket(std::move(ticket_buffer));
|
||||
const IOS::ES::TicketReader ticket(std::move(ticket_buffer));
|
||||
if (ticket.IsValid())
|
||||
partition->SetKey(ticket.GetTitleKey());
|
||||
}
|
||||
|
@ -1024,7 +1024,7 @@ u64 DirectoryBlobPartition::SetApploader(std::vector<u8> apploader, const std::s
|
|||
Write32(static_cast<u32>(-1), 0x10, &apploader);
|
||||
}
|
||||
|
||||
size_t apploader_size = apploader.size();
|
||||
const size_t apploader_size = apploader.size();
|
||||
m_contents.Add(APPLOADER_ADDRESS, std::move(apploader));
|
||||
|
||||
// Return DOL address, 32 byte aligned (plus 32 byte padding)
|
||||
|
@ -1125,10 +1125,10 @@ void DirectoryBlobPartition::BuildFST(std::vector<FSTBuilderNode> root_nodes, u6
|
|||
{
|
||||
ConvertUTF8NamesToSHIFTJIS(&root_nodes);
|
||||
|
||||
u32 name_table_size = Common::AlignUp(ComputeNameSize(root_nodes), 1ull << m_address_shift);
|
||||
const u32 name_table_size = Common::AlignUp(ComputeNameSize(root_nodes), 1ull << m_address_shift);
|
||||
|
||||
// 1 extra for the root entry
|
||||
u64 total_entries = RecalculateFolderSizes(&root_nodes) + 1;
|
||||
const u64 total_entries = RecalculateFolderSizes(&root_nodes) + 1;
|
||||
|
||||
const u64 name_table_offset = total_entries * ENTRY_SIZE;
|
||||
std::vector<u8> fst_data(name_table_offset + name_table_size);
|
||||
|
@ -1136,9 +1136,9 @@ void DirectoryBlobPartition::BuildFST(std::vector<FSTBuilderNode> root_nodes, u6
|
|||
// 32 KiB aligned start of data on disc
|
||||
u64 current_data_address = Common::AlignUp(fst_address + fst_data.size(), 0x8000ull);
|
||||
|
||||
u32 fst_offset = 0; // Offset within FST data
|
||||
u32 name_offset = 0; // Offset within name table
|
||||
u32 root_offset = 0; // Offset of root of FST
|
||||
u32 fst_offset = 0; // Offset within FST data
|
||||
u32 name_offset = 0; // Offset within name table
|
||||
const u32 root_offset = 0; // Offset of root of FST
|
||||
|
||||
// write root entry
|
||||
WriteEntryData(&fst_data, &fst_offset, DIRECTORY_ENTRY, 0, 0, total_entries, m_address_shift);
|
||||
|
@ -1204,7 +1204,7 @@ void DirectoryBlobPartition::WriteDirectory(std::vector<u8>* fst_data,
|
|||
{
|
||||
if (entry.IsFolder())
|
||||
{
|
||||
u32 entry_index = *fst_offset / ENTRY_SIZE;
|
||||
const u32 entry_index = *fst_offset / ENTRY_SIZE;
|
||||
WriteEntryData(fst_data, fst_offset, DIRECTORY_ENTRY, *name_offset, parent_entry_index,
|
||||
entry_index + entry.m_size + 1, 0);
|
||||
WriteEntryName(fst_data, name_offset, entry.m_filename, name_table_offset);
|
||||
|
@ -1246,7 +1246,7 @@ static void PadToAddress(u64 start_address, u64* address, u64* length, u8** buff
|
|||
{
|
||||
if (start_address > *address && *length > 0)
|
||||
{
|
||||
u64 padBytes = std::min(start_address - *address, *length);
|
||||
const u64 padBytes = std::min(start_address - *address, *length);
|
||||
memset(*buffer, 0, (size_t)padBytes);
|
||||
*length -= padBytes;
|
||||
*buffer += padBytes;
|
||||
|
|
|
@ -161,7 +161,7 @@ class DiscContentContainer
|
|||
public:
|
||||
void Add(u64 offset, std::vector<u8> vector)
|
||||
{
|
||||
size_t vector_size = vector.size();
|
||||
const size_t vector_size = vector.size();
|
||||
return Add(offset, vector_size, std::make_shared<std::vector<u8>>(std::move(vector)));
|
||||
}
|
||||
void Add(u64 offset, u64 size, ContentSource source);
|
||||
|
|
|
@ -72,7 +72,7 @@ void DiscScrubber::MarkAsUsedE(u64 partition_data_offset, u64 offset, u64 size)
|
|||
}
|
||||
else
|
||||
{
|
||||
u64 first_cluster_start = ToClusterOffset(offset) + partition_data_offset;
|
||||
const u64 first_cluster_start = ToClusterOffset(offset) + partition_data_offset;
|
||||
|
||||
u64 last_cluster_end;
|
||||
if (size == 0)
|
||||
|
@ -102,7 +102,7 @@ u64 DiscScrubber::ToClusterOffset(u64 offset) const
|
|||
bool DiscScrubber::ReadFromVolume(const Volume& disc, u64 offset, u32& buffer,
|
||||
const Partition& partition)
|
||||
{
|
||||
std::optional<u32> value = disc.ReadSwapped<u32>(offset, partition);
|
||||
const std::optional<u32> value = disc.ReadSwapped<u32>(offset, partition);
|
||||
if (value)
|
||||
buffer = *value;
|
||||
return value.has_value();
|
||||
|
@ -111,7 +111,7 @@ bool DiscScrubber::ReadFromVolume(const Volume& disc, u64 offset, u32& buffer,
|
|||
bool DiscScrubber::ReadFromVolume(const Volume& disc, u64 offset, u64& buffer,
|
||||
const Partition& partition)
|
||||
{
|
||||
std::optional<u64> value = disc.ReadSwappedAndShifted(offset, partition);
|
||||
const std::optional<u64> value = disc.ReadSwappedAndShifted(offset, partition);
|
||||
if (value)
|
||||
buffer = *value;
|
||||
return value.has_value();
|
||||
|
|
|
@ -875,7 +875,7 @@ const std::string& GetCompanyFromID(const std::string& company_id)
|
|||
{"ZX", "TopWare Interactive"}};
|
||||
|
||||
static const std::string EMPTY_STRING;
|
||||
auto iterator = companies.find(company_id);
|
||||
const auto iterator = companies.find(company_id);
|
||||
if (iterator != companies.end())
|
||||
return iterator->second;
|
||||
else
|
||||
|
|
|
@ -76,7 +76,7 @@ bool ConvertToPlain(BlobReader* infile, const std::string& infile_path,
|
|||
|
||||
std::vector<u8> buffer(buffer_size);
|
||||
const u64 num_buffers = (infile->GetDataSize() + buffer_size - 1) / buffer_size;
|
||||
int progress_monitor = std::max<int>(1, num_buffers / 100);
|
||||
const int progress_monitor = std::max<int>(1, num_buffers / 100);
|
||||
bool success = true;
|
||||
|
||||
for (u64 i = 0; i < num_buffers; i++)
|
||||
|
|
|
@ -165,7 +165,7 @@ std::string FileInfoGCWii::GetPath() const
|
|||
|
||||
if (IsDirectory())
|
||||
{
|
||||
u32 parent_directory_index = Get(EntryProperty::FILE_OFFSET);
|
||||
const u32 parent_directory_index = Get(EntryProperty::FILE_OFFSET);
|
||||
return FileInfoGCWii(*this, parent_directory_index).GetPath() + GetName() + "/";
|
||||
}
|
||||
else
|
||||
|
@ -345,7 +345,7 @@ std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(u64 disc_offset) const
|
|||
// Build a cache (unless there already is one)
|
||||
if (m_offset_file_info_cache.empty())
|
||||
{
|
||||
u32 fst_entries = m_root.GetSize();
|
||||
const u32 fst_entries = m_root.GetSize();
|
||||
for (u32 i = 0; i < fst_entries; i++)
|
||||
{
|
||||
FileInfoGCWii file_info(m_root, i);
|
||||
|
|
|
@ -208,7 +208,7 @@ std::string WriteGameModDescriptorString(const GameModDescriptor& descriptor, bo
|
|||
bool WriteGameModDescriptorFile(const std::string& filename, const GameModDescriptor& descriptor,
|
||||
bool pretty)
|
||||
{
|
||||
auto json = WriteGameModDescriptorString(descriptor, pretty);
|
||||
const auto json = WriteGameModDescriptorString(descriptor, pretty);
|
||||
if (json.empty())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -137,7 +137,8 @@ private:
|
|||
{
|
||||
CompressThreadState compress_thread_state;
|
||||
|
||||
ConversionResultCode setup_result = m_set_up_compress_thread_state(&compress_thread_state);
|
||||
const ConversionResultCode setup_result =
|
||||
m_set_up_compress_thread_state(&compress_thread_state);
|
||||
if (setup_result != ConversionResultCode::Success)
|
||||
SetError(setup_result);
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ bool NANDImporter::FindSuperblock()
|
|||
|
||||
std::string NANDImporter::GetPath(const NANDFSTEntry& entry, const std::string& parent_path)
|
||||
{
|
||||
std::string name(entry.name, strnlen(entry.name, sizeof(NANDFSTEntry::name)));
|
||||
const std::string name(entry.name, strnlen(entry.name, sizeof(NANDFSTEntry::name)));
|
||||
|
||||
if (name.front() == '/' || parent_path.back() == '/')
|
||||
return parent_path + name;
|
||||
|
@ -147,7 +147,7 @@ void NANDImporter::ProcessEntry(u16 entry_number, const std::string& parent_path
|
|||
INFO_LOG_FMT(DISCIO, "Entry: {} Path: {}", entry, path);
|
||||
m_update_callback();
|
||||
|
||||
Type type = static_cast<Type>(entry.mode & 3);
|
||||
const Type type = static_cast<Type>(entry.mode & 3);
|
||||
if (type == Type::File)
|
||||
{
|
||||
std::vector<u8> data = GetEntryData(entry);
|
||||
|
@ -177,7 +177,7 @@ std::vector<u8> NANDImporter::GetEntryData(const NANDFSTEntry& entry)
|
|||
std::vector<u8> data{};
|
||||
data.reserve(remaining_bytes);
|
||||
|
||||
auto block = std::make_unique<u8[]>(NAND_FAT_BLOCK_SIZE);
|
||||
const auto block = std::make_unique<u8[]>(NAND_FAT_BLOCK_SIZE);
|
||||
while (remaining_bytes > 0)
|
||||
{
|
||||
if (sub >= m_superblock->fat.size())
|
||||
|
@ -188,7 +188,7 @@ std::vector<u8> NANDImporter::GetEntryData(const NANDFSTEntry& entry)
|
|||
|
||||
m_aes_ctx->CryptIvZero(&m_nand[NAND_FAT_BLOCK_SIZE * sub], block.get(), NAND_FAT_BLOCK_SIZE);
|
||||
|
||||
size_t size = std::min(remaining_bytes, NAND_FAT_BLOCK_SIZE);
|
||||
const size_t size = std::min(remaining_bytes, NAND_FAT_BLOCK_SIZE);
|
||||
data.insert(data.end(), block.get(), block.get() + size);
|
||||
remaining_bytes -= size;
|
||||
|
||||
|
@ -210,7 +210,7 @@ bool NANDImporter::ExtractCertificates()
|
|||
return false;
|
||||
}
|
||||
|
||||
IOS::ES::TMDReader tmd(std::move(tmd_bytes));
|
||||
const IOS::ES::TMDReader tmd(std::move(tmd_bytes));
|
||||
IOS::ES::Content content_metadata;
|
||||
if (!tmd.GetContent(tmd.GetBootIndex(), &content_metadata))
|
||||
{
|
||||
|
|
|
@ -277,7 +277,7 @@ std::vector<Patch> Disc::GeneratePatches(const std::string& game_id) const
|
|||
{
|
||||
if (sv.starts_with(r.first))
|
||||
{
|
||||
for (char c : r.second)
|
||||
for (const char c : r.second)
|
||||
result.push_back(c);
|
||||
sv = sv.substr(r.first.size());
|
||||
replaced = true;
|
||||
|
@ -478,7 +478,7 @@ std::string WriteConfigString(const Config& config)
|
|||
|
||||
bool WriteConfigFile(const std::string& filename, const Config& config)
|
||||
{
|
||||
auto xml = WriteConfigString(config);
|
||||
const auto xml = WriteConfigString(config);
|
||||
if (xml.empty())
|
||||
return false;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ FileDataLoaderHostFS::FileDataLoaderHostFS(std::string sd_root, const std::strin
|
|||
// m_patch_root with it.
|
||||
if (!patch_root.empty())
|
||||
{
|
||||
auto r = MakeAbsoluteFromRelative(patch_root);
|
||||
const auto r = MakeAbsoluteFromRelative(patch_root);
|
||||
if (r)
|
||||
m_patch_root = std::move(*r);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ FileDataLoaderHostFS::MakeAbsoluteFromRelative(std::string_view external_relativ
|
|||
break;
|
||||
|
||||
// Extract a single path element.
|
||||
size_t separator_position = work.find('/');
|
||||
const size_t separator_position = work.find('/');
|
||||
std::string_view element = work.substr(0, separator_position);
|
||||
|
||||
if (element == ".")
|
||||
|
@ -165,10 +165,10 @@ FileDataLoaderHostFS::MakeAbsoluteFromRelative(std::string_view external_relativ
|
|||
std::optional<u64>
|
||||
FileDataLoaderHostFS::GetExternalFileSize(std::string_view external_relative_path)
|
||||
{
|
||||
auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
const auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
if (!path)
|
||||
return std::nullopt;
|
||||
::File::FileInfo f(*path);
|
||||
const ::File::FileInfo f(*path);
|
||||
if (!f.IsFile())
|
||||
return std::nullopt;
|
||||
return f.GetSize();
|
||||
|
@ -176,7 +176,7 @@ FileDataLoaderHostFS::GetExternalFileSize(std::string_view external_relative_pat
|
|||
|
||||
std::vector<u8> FileDataLoaderHostFS::GetFileContents(std::string_view external_relative_path)
|
||||
{
|
||||
auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
const auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
if (!path)
|
||||
return {};
|
||||
::File::IOFile f(*path, "rb");
|
||||
|
@ -193,7 +193,7 @@ std::vector<u8> FileDataLoaderHostFS::GetFileContents(std::string_view external_
|
|||
std::vector<FileDataLoader::Node>
|
||||
FileDataLoaderHostFS::GetFolderContents(std::string_view external_relative_path)
|
||||
{
|
||||
auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
const auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
if (!path)
|
||||
return {};
|
||||
::File::FSTEntry external_files = ::File::ScanDirectoryTree(*path, false);
|
||||
|
@ -208,7 +208,7 @@ BuilderContentSource
|
|||
FileDataLoaderHostFS::MakeContentSource(std::string_view external_relative_path,
|
||||
u64 external_offset, u64 external_size, u64 disc_offset)
|
||||
{
|
||||
auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
const auto path = MakeAbsoluteFromRelative(external_relative_path);
|
||||
if (!path)
|
||||
return BuilderContentSource{disc_offset, external_size, ContentFixedByte{0}};
|
||||
return BuilderContentSource{disc_offset, external_size,
|
||||
|
@ -514,7 +514,7 @@ static bool MemoryMatchesAt(const Core::CPUThreadGuard& guard, u32 offset,
|
|||
{
|
||||
for (u32 i = 0; i < value.size(); ++i)
|
||||
{
|
||||
auto result = PowerPC::MMU::HostTryReadU8(guard, offset + i);
|
||||
const auto result = PowerPC::MMU::HostTryReadU8(guard, offset + i);
|
||||
if (!result || result->value != value[i])
|
||||
return false;
|
||||
}
|
||||
|
@ -600,7 +600,7 @@ static void ApplyOcarinaMemoryPatch(const Core::CPUThreadGuard& guard, const Pat
|
|||
{
|
||||
// from the pattern find the next blr instruction
|
||||
const u32 blr_address = ram_start + i;
|
||||
auto blr = PowerPC::MMU::HostTryReadU32(guard, blr_address);
|
||||
const auto blr = PowerPC::MMU::HostTryReadU32(guard, blr_address);
|
||||
if (blr && blr->value == 0x4e800020)
|
||||
{
|
||||
// and replace it with a jump to the given offset
|
||||
|
@ -666,7 +666,8 @@ std::optional<SavegameRedirect> ExtractSavegameRedirect(std::span<const Patch> r
|
|||
if (!patch.m_savegame_patches.empty())
|
||||
{
|
||||
const auto& save_patch = patch.m_savegame_patches[0];
|
||||
auto resolved = patch.m_file_data_loader->ResolveSavegameRedirectPath(save_patch.m_external);
|
||||
const auto resolved =
|
||||
patch.m_file_data_loader->ResolveSavegameRedirectPath(save_patch.m_external);
|
||||
if (resolved)
|
||||
return SavegameRedirect{std::move(*resolved), save_patch.m_clone};
|
||||
return std::nullopt;
|
||||
|
|
|
@ -22,7 +22,7 @@ ScrubbedBlob::ScrubbedBlob(std::unique_ptr<BlobReader> blob_reader, DiscScrubber
|
|||
|
||||
std::unique_ptr<ScrubbedBlob> ScrubbedBlob::Create(const std::string& path)
|
||||
{
|
||||
std::unique_ptr<VolumeDisc> disc = CreateDisc(path);
|
||||
const std::unique_ptr<VolumeDisc> disc = CreateDisc(path);
|
||||
if (!disc)
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ std::string VolumeDisc::GetMakerID(const Partition& partition) const
|
|||
|
||||
std::optional<u16> VolumeDisc::GetRevision(const Partition& partition) const
|
||||
{
|
||||
std::optional<u8> revision = ReadSwapped<u8>(7, partition);
|
||||
const std::optional<u8> revision = ReadSwapped<u8>(7, partition);
|
||||
return revision ? *revision : std::optional<u16>();
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ void VolumeDisc::AddGamePartitionToSyncHash(Common::SHA1::Context* context) cons
|
|||
const FileSystem* file_system = GetFileSystem(partition);
|
||||
if (file_system)
|
||||
{
|
||||
std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo("opening.bnr");
|
||||
const std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo("opening.bnr");
|
||||
if (file_info && !file_info->IsDirectory())
|
||||
ReadAndAddToSyncHash(context, file_info->GetOffset(), file_info->GetSize(), partition);
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ bool VolumeGC::IsDatelDisc() const
|
|||
|
||||
std::array<u8, 20> VolumeGC::GetSyncHash() const
|
||||
{
|
||||
auto context = Common::SHA1::CreateContext();
|
||||
const auto context = Common::SHA1::CreateContext();
|
||||
|
||||
AddGamePartitionToSyncHash(context.get());
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ RedumpVerifier::DownloadStatus RedumpVerifier::DownloadDatfile(const std::string
|
|||
|
||||
std::vector<u8> RedumpVerifier::ReadDatfile(const std::string& system)
|
||||
{
|
||||
unzFile file = unzOpen(GetPathForSystem(system).c_str());
|
||||
const unzFile file = unzOpen(GetPathForSystem(system).c_str());
|
||||
if (!file)
|
||||
return {};
|
||||
|
||||
|
@ -432,7 +432,8 @@ std::vector<Partition> VolumeVerifier::CheckPartitions()
|
|||
return {m_volume.GetGamePartition()};
|
||||
}
|
||||
|
||||
std::optional<u32> partitions_in_first_table = m_volume.ReadSwapped<u32>(0x40000, PARTITION_NONE);
|
||||
const std::optional<u32> partitions_in_first_table =
|
||||
m_volume.ReadSwapped<u32>(0x40000, PARTITION_NONE);
|
||||
if (partitions_in_first_table && *partitions_in_first_table > 8)
|
||||
{
|
||||
// Not sure if 8 actually is the limit, but there certainly aren't any discs
|
||||
|
@ -1023,7 +1024,7 @@ void VolumeVerifier::CheckSuperPaperMario()
|
|||
if (!fs)
|
||||
return;
|
||||
|
||||
std::unique_ptr<FileInfo> file_info = fs->FindFileInfo("setup/aa1_01.dat");
|
||||
const std::unique_ptr<FileInfo> file_info = fs->FindFileInfo("setup/aa1_01.dat");
|
||||
if (!file_info)
|
||||
return;
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ bool VolumeWAD::CheckContentIntegrity(const IOS::ES::Content& content,
|
|||
if (encrypted_data.size() != Common::AlignUp(content.size, 0x40))
|
||||
return false;
|
||||
|
||||
auto context = Common::AES::CreateContextDecrypt(ticket.GetTitleKey().data());
|
||||
const auto context = Common::AES::CreateContextDecrypt(ticket.GetTitleKey().data());
|
||||
|
||||
std::array<u8, 16> iv{};
|
||||
iv[0] = static_cast<u8>(content.index >> 8);
|
||||
|
@ -334,7 +334,7 @@ std::array<u8, 20> VolumeWAD::GetSyncHash() const
|
|||
// We can skip hashing the contents since the TMD contains hashes of the contents.
|
||||
// We specifically don't hash the ticket, since its console ID can differ without any problems.
|
||||
|
||||
auto context = Common::SHA1::CreateContext();
|
||||
const auto context = Common::SHA1::CreateContext();
|
||||
|
||||
AddTMDToSyncHash(context.get(), PARTITION_NONE);
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ bool VolumeWii::Read(u64 offset, u64 length, u8* buffer, const Partition& partit
|
|||
if (partition == PARTITION_NONE)
|
||||
return m_reader->Read(offset, length, buffer);
|
||||
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
if (it == m_partitions.end())
|
||||
return false;
|
||||
const PartitionDetails& partition_details = it->second;
|
||||
|
@ -199,8 +199,9 @@ bool VolumeWii::Read(u64 offset, u64 length, u8* buffer, const Partition& partit
|
|||
while (length > 0)
|
||||
{
|
||||
// Calculate offsets
|
||||
u64 block_offset_on_disc = partition_data_offset + offset / BLOCK_DATA_SIZE * BLOCK_TOTAL_SIZE;
|
||||
u64 data_offset_in_block = offset % BLOCK_DATA_SIZE;
|
||||
const u64 block_offset_on_disc =
|
||||
partition_data_offset + offset / BLOCK_DATA_SIZE * BLOCK_TOTAL_SIZE;
|
||||
const u64 data_offset_in_block = offset % BLOCK_DATA_SIZE;
|
||||
|
||||
if (m_last_decrypted_block != block_offset_on_disc)
|
||||
{
|
||||
|
@ -227,7 +228,7 @@ bool VolumeWii::Read(u64 offset, u64 length, u8* buffer, const Partition& partit
|
|||
}
|
||||
|
||||
// Copy the decrypted data
|
||||
u64 copy_size = std::min(length, BLOCK_DATA_SIZE - data_offset_in_block);
|
||||
const u64 copy_size = std::min(length, BLOCK_DATA_SIZE - data_offset_in_block);
|
||||
memcpy(buffer, &m_last_decrypted_block_data[data_offset_in_block],
|
||||
static_cast<size_t>(copy_size));
|
||||
|
||||
|
@ -265,7 +266,7 @@ Partition VolumeWii::GetGamePartition() const
|
|||
|
||||
std::optional<u32> VolumeWii::GetPartitionType(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? it->second.type : std::optional<u32>();
|
||||
}
|
||||
|
||||
|
@ -279,25 +280,25 @@ std::optional<u64> VolumeWii::GetTitleID(const Partition& partition) const
|
|||
|
||||
const IOS::ES::TicketReader& VolumeWii::GetTicket(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? *it->second.ticket : INVALID_TICKET;
|
||||
}
|
||||
|
||||
const IOS::ES::TMDReader& VolumeWii::GetTMD(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? *it->second.tmd : INVALID_TMD;
|
||||
}
|
||||
|
||||
const std::vector<u8>& VolumeWii::GetCertificateChain(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? *it->second.cert_chain : INVALID_CERT_CHAIN;
|
||||
}
|
||||
|
||||
const FileSystem* VolumeWii::GetFileSystem(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
return it != m_partitions.end() ? it->second.file_system->get() : nullptr;
|
||||
}
|
||||
|
||||
|
@ -313,7 +314,7 @@ u64 VolumeWii::OffsetInHashedPartitionToRawOffset(u64 offset, const Partition& p
|
|||
|
||||
u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
if (it == m_partitions.end())
|
||||
return offset;
|
||||
const u64 data_offset = *it->second.data_offset;
|
||||
|
@ -391,7 +392,7 @@ const BlobReader& VolumeWii::GetBlobReader() const
|
|||
|
||||
std::array<u8, 20> VolumeWii::GetSyncHash() const
|
||||
{
|
||||
auto context = Common::SHA1::CreateContext();
|
||||
const auto context = Common::SHA1::CreateContext();
|
||||
|
||||
// Disc header
|
||||
ReadAndAddToSyncHash(context.get(), 0, 0x80, PARTITION_NONE);
|
||||
|
@ -414,7 +415,7 @@ std::array<u8, 20> VolumeWii::GetSyncHash() const
|
|||
|
||||
bool VolumeWii::CheckH3TableIntegrity(const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
if (it == m_partitions.end())
|
||||
return false;
|
||||
const PartitionDetails& partition_details = it->second;
|
||||
|
@ -437,7 +438,7 @@ bool VolumeWii::CheckH3TableIntegrity(const Partition& partition) const
|
|||
bool VolumeWii::CheckBlockIntegrity(u64 block_index, const u8* encrypted_data,
|
||||
const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
if (it == m_partitions.end())
|
||||
return false;
|
||||
const PartitionDetails& partition_details = it->second;
|
||||
|
@ -484,7 +485,7 @@ bool VolumeWii::CheckBlockIntegrity(u64 block_index, const u8* encrypted_data,
|
|||
return false;
|
||||
|
||||
Common::SHA1::Digest h3_digest;
|
||||
auto h3_digest_ptr =
|
||||
const auto h3_digest_ptr =
|
||||
partition_details.h3_table->data() + block_index / 64 * Common::SHA1::DIGEST_LEN;
|
||||
memcpy(h3_digest.data(), h3_digest_ptr, sizeof(h3_digest));
|
||||
if (Common::SHA1::CalculateDigest(hashes.h2) != h3_digest)
|
||||
|
@ -495,7 +496,7 @@ bool VolumeWii::CheckBlockIntegrity(u64 block_index, const u8* encrypted_data,
|
|||
|
||||
bool VolumeWii::CheckBlockIntegrity(u64 block_index, const Partition& partition) const
|
||||
{
|
||||
auto it = m_partitions.find(partition);
|
||||
const auto it = m_partitions.find(partition);
|
||||
if (it == m_partitions.end())
|
||||
return false;
|
||||
const PartitionDetails& partition_details = it->second;
|
||||
|
|
|
@ -2053,7 +2053,7 @@ bool ConvertToWIAOrRVZ(BlobReader* infile, const std::string& infile_path,
|
|||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<VolumeDisc> infile_volume = CreateDisc(infile_path);
|
||||
const std::unique_ptr<VolumeDisc> infile_volume = CreateDisc(infile_path);
|
||||
|
||||
const auto convert = rvz ? RVZFileReader::Convert : WIAFileReader::Convert;
|
||||
const ConversionResultCode result =
|
||||
|
|
|
@ -151,12 +151,12 @@ bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
|||
|
||||
File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
|
||||
{
|
||||
u64 base_cluster = (offset >> m_header.wbfs_sector_shift);
|
||||
const u64 base_cluster = (offset >> m_header.wbfs_sector_shift);
|
||||
if (base_cluster < m_blocks_per_disc)
|
||||
{
|
||||
u64 cluster_address = m_wbfs_sector_size * m_wlba_table[base_cluster];
|
||||
u64 cluster_offset = offset & (m_wbfs_sector_size - 1);
|
||||
u64 final_address = cluster_address + cluster_offset;
|
||||
const u64 cluster_address = m_wbfs_sector_size * m_wlba_table[base_cluster];
|
||||
const u64 cluster_offset = offset & (m_wbfs_sector_size - 1);
|
||||
const u64 final_address = cluster_address + cluster_offset;
|
||||
|
||||
for (FileEntry& file_entry : m_files)
|
||||
{
|
||||
|
@ -165,8 +165,8 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
|
|||
file_entry.file.Seek(final_address - file_entry.base_address, File::SeekOrigin::Begin);
|
||||
if (available)
|
||||
{
|
||||
u64 till_end_of_file = file_entry.size - (final_address - file_entry.base_address);
|
||||
u64 till_end_of_sector = m_wbfs_sector_size - cluster_offset;
|
||||
const u64 till_end_of_file = file_entry.size - (final_address - file_entry.base_address);
|
||||
const u64 till_end_of_sector = m_wbfs_sector_size - cluster_offset;
|
||||
*available = std::min(till_end_of_file, till_end_of_sector);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue