From 443729d2c31af894f8e0d0d118de3afceced29f9 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 18 Nov 2018 18:27:18 +0100 Subject: [PATCH] GCMemcard: Use BigEndianValue for DEntry.m_comments_address. --- Source/Core/Core/HW/GCMemcard/GCMemcard.cpp | 13 ++++++++----- Source/Core/Core/HW/GCMemcard/GCMemcard.h | 9 +++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index 51275c4aee..544c934716 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -533,7 +533,7 @@ u32 GCMemcard::DEntry_CommentsAddress(u8 index) const if (!m_valid || index >= DIRLEN) return 0xFFFF; - return BE32(CurrentDir->m_dir_entries[index].m_comments_address); + return CurrentDir->m_dir_entries[index].m_comments_address; } std::string GCMemcard::GetSaveComment1(u8 index) const @@ -541,7 +541,7 @@ std::string GCMemcard::GetSaveComment1(u8 index) const if (!m_valid || index >= DIRLEN) return ""; - u32 Comment1 = BE32(CurrentDir->m_dir_entries[index].m_comments_address); + u32 Comment1 = CurrentDir->m_dir_entries[index].m_comments_address; u32 DataBlock = CurrentDir->m_dir_entries[index].m_first_block - MC_FST_BLOCKS; if ((DataBlock > maxBlock) || (Comment1 == 0xFFFFFFFF)) { @@ -555,7 +555,7 @@ std::string GCMemcard::GetSaveComment2(u8 index) const if (!m_valid || index >= DIRLEN) return ""; - u32 Comment1 = BE32(CurrentDir->m_dir_entries[index].m_comments_address); + u32 Comment1 = CurrentDir->m_dir_entries[index].m_comments_address; u32 Comment2 = Comment1 + DENTRY_STRLEN; u32 DataBlock = CurrentDir->m_dir_entries[index].m_first_block - MC_FST_BLOCKS; if ((DataBlock > maxBlock) || (Comment1 == 0xFFFFFFFF)) @@ -1070,8 +1070,11 @@ void GCMemcard::Gcs_SavConvert(DEntry& tempDEntry, int saveType, int length) memcpy(&tempDEntry.m_block_count, tmp.data(), 2); ArrayByteSwap((tempDEntry.m_unused_2)); - ArrayByteSwap((tempDEntry.m_comments_address)); - ArrayByteSwap(&(tempDEntry.m_comments_address[2])); + + memcpy(tmp.data(), &tempDEntry.m_comments_address, 4); + ByteSwap(&tmp[0], &tmp[1]); + ByteSwap(&tmp[2], &tmp[3]); + memcpy(&tempDEntry.m_comments_address, tmp.data(), 4); break; default: break; diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.h b/Source/Core/Core/HW/GCMemcard/GCMemcard.h index 985d8021b1..fc26fc9499 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.h @@ -216,10 +216,11 @@ struct DEntry Common::BigEndianValue m_first_block; // 0x36 0x02 Block no of first block of file (0 == offset 0) Common::BigEndianValue - m_block_count; // 0x38 0x02 File-length (number of blocks in file) - u8 m_unused_2[2]; // 0x3a 0x02 Reserved/unused (always 0xffff, has no effect) - u8 m_comments_address[4]; // 0x3c 0x04 Address of the two comments within the file data - // (*3) + m_block_count; // 0x38 0x02 File-length (number of blocks in file) + u8 m_unused_2[2]; // 0x3a 0x02 Reserved/unused (always 0xffff, has no effect) + Common::BigEndianValue + m_comments_address; // 0x3c 0x04 Address of the two comments within the file data + // (*3) }; static_assert(sizeof(DEntry) == DENTRY_SIZE);