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/VolumeWad.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Source/Core/DiscIO/VolumeWad.cpp') diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index b7b8fa35cd..86aebb20b6 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -40,6 +40,7 @@ VolumeWAD::VolumeWAD(std::unique_ptr reader) : m_reader(std::move(re m_ticket_size = m_reader->ReadSwapped(0x10).value_or(0); m_tmd_size = m_reader->ReadSwapped(0x14).value_or(0); m_data_size = m_reader->ReadSwapped(0x18).value_or(0); + m_opening_bnr_size = m_reader->ReadSwapped(0x1C).value_or(0); m_cert_chain_offset = Common::AlignUp(m_hdr_size, 0x40); m_ticket_offset = m_cert_chain_offset + Common::AlignUp(m_cert_chain_size, 0x40); @@ -342,4 +343,22 @@ const BlobReader& VolumeWAD::GetBlobReader() const return *m_reader; } +std::array 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. + + mbedtls_sha1_context context; + mbedtls_sha1_init(&context); + mbedtls_sha1_starts_ret(&context); + + AddTMDToSyncHash(&context, PARTITION_NONE); + + ReadAndAddToSyncHash(&context, m_opening_bnr_offset, m_opening_bnr_size, PARTITION_NONE); + + std::array hash; + mbedtls_sha1_finish_ret(&context, hash.data()); + return hash; +} + } // namespace DiscIO -- cgit v1.2.3