From a41166bb376820389d9863ce23cf6fab20cb3b5f Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 7 Jun 2020 22:58:03 +0200 Subject: Make netplay's "same game" check more robust Instead of comparing the game ID, revision, disc number and name, we can compare a hash of important parts of the disc including all the aforementioned data but also additional data such as the FST. The primary reason why I'm making this change is to let us catch more desyncs before they happen, but this should also fix https://bugs.dolphin-emu.org/issues/12115. As a bonus, the UI can now distinguish the case where a client doesn't have the game at all from the case where a client has the wrong version of the game. --- Source/Core/DiscIO/VolumeDisc.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'Source/Core/DiscIO/VolumeDisc.cpp') diff --git a/Source/Core/DiscIO/VolumeDisc.cpp b/Source/Core/DiscIO/VolumeDisc.cpp index fed82a8067..3ccea4b62f 100644 --- a/Source/Core/DiscIO/VolumeDisc.cpp +++ b/Source/Core/DiscIO/VolumeDisc.cpp @@ -4,11 +4,17 @@ #include "DiscIO/VolumeDisc.h" +#include #include #include +#include + +#include #include "Common/CommonTypes.h" +#include "DiscIO/DiscExtractor.h" #include "DiscIO/Enums.h" +#include "DiscIO/Filesystem.h" namespace DiscIO { @@ -90,4 +96,35 @@ bool VolumeDisc::IsNKit() const return ReadSwapped(0x200, PARTITION_NONE) == NKIT_MAGIC; } +void VolumeDisc::AddGamePartitionToSyncHash(mbedtls_sha1_context* context) const +{ + const Partition partition = GetGamePartition(); + + // All headers at the beginning of the partition, plus the apploader + ReadAndAddToSyncHash(context, 0, 0x2440 + GetApploaderSize(*this, partition).value_or(0), + partition); + + // Boot DOL (may be missing if this is a Datel disc) + const std::optional dol_offset = GetBootDOLOffset(*this, partition); + if (dol_offset) + { + ReadAndAddToSyncHash(context, *dol_offset, + GetBootDOLSize(*this, partition, *dol_offset).value_or(0), partition); + } + + // File system + const std::optional fst_offset = GetFSTOffset(*this, partition); + if (fst_offset) + ReadAndAddToSyncHash(context, *fst_offset, GetFSTSize(*this, partition).value_or(0), partition); + + // opening.bnr (name and banner) + const FileSystem* file_system = GetFileSystem(partition); + if (file_system) + { + std::unique_ptr file_info = file_system->FindFileInfo("opening.bnr"); + if (file_info && !file_info->IsDirectory()) + ReadAndAddToSyncHash(context, file_info->GetOffset(), file_info->GetSize(), partition); + } +} + } // namespace DiscIO -- cgit v1.2.3