diff options
| author | JosJuice <josjuice@gmail.com> | 2020-06-07 22:58:03 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2020-08-02 22:46:53 +0200 |
| commit | a41166bb376820389d9863ce23cf6fab20cb3b5f (patch) | |
| tree | 833fb8c0479af02a23f88d650838d542fa012b00 /Source/Core/DiscIO/VolumeDisc.cpp | |
| parent | 25ebc3c07c6310924d662b2209f9ba5d08006ea6 (diff) | |
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.
Diffstat (limited to 'Source/Core/DiscIO/VolumeDisc.cpp')
| -rw-r--r-- | Source/Core/DiscIO/VolumeDisc.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
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 <memory> #include <optional> #include <string> +#include <vector> + +#include <mbedtls/sha1.h> #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<u32>(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<u64> 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<u64> 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<FileInfo> file_info = file_system->FindFileInfo("opening.bnr"); + if (file_info && !file_info->IsDirectory()) + ReadAndAddToSyncHash(context, file_info->GetOffset(), file_info->GetSize(), partition); + } +} + } // namespace DiscIO |
