GCMemcard: Use std::array for GCMBlock.m_block.

This commit is contained in:
Admiral H. Curtiss 2018-12-01 17:04:17 +01:00
parent ceb9cb53c6
commit 3d77a43e67
3 changed files with 16 additions and 14 deletions

View File

@ -188,7 +188,7 @@ GCMemcard::GCMemcard(const std::string& filename, bool forceCreation, bool shift
for (u32 i = MC_FST_BLOCKS; i < m_size_blocks; ++i) for (u32 i = MC_FST_BLOCKS; i < m_size_blocks; ++i)
{ {
GCMBlock b; GCMBlock b;
if (mcdFile.ReadBytes(b.m_block, BLOCK_SIZE)) if (mcdFile.ReadBytes(b.m_block.data(), b.m_block.size()))
{ {
m_data_blocks.push_back(b); m_data_blocks.push_back(b);
} }
@ -263,7 +263,7 @@ bool GCMemcard::Save()
mcdFile.WriteBytes(&m_bat_blocks[1], BLOCK_SIZE); mcdFile.WriteBytes(&m_bat_blocks[1], BLOCK_SIZE);
for (unsigned int i = 0; i < m_size_blocks - MC_FST_BLOCKS; ++i) for (unsigned int i = 0; i < m_size_blocks - MC_FST_BLOCKS; ++i)
{ {
mcdFile.WriteBytes(m_data_blocks[i].m_block, BLOCK_SIZE); mcdFile.WriteBytes(m_data_blocks[i].m_block.data(), m_data_blocks[i].m_block.size());
} }
return mcdFile.Close(); return mcdFile.Close();
@ -575,7 +575,8 @@ std::string GCMemcard::GetSaveComment1(u8 index) const
{ {
return ""; return "";
} }
return std::string((const char*)m_data_blocks[DataBlock].m_block + Comment1, DENTRY_STRLEN); return std::string((const char*)m_data_blocks[DataBlock].m_block.data() + Comment1,
DENTRY_STRLEN);
} }
std::string GCMemcard::GetSaveComment2(u8 index) const std::string GCMemcard::GetSaveComment2(u8 index) const
@ -590,7 +591,8 @@ std::string GCMemcard::GetSaveComment2(u8 index) const
{ {
return ""; return "";
} }
return std::string((const char*)m_data_blocks[DataBlock].m_block + Comment2, DENTRY_STRLEN); return std::string((const char*)m_data_blocks[DataBlock].m_block.data() + Comment2,
DENTRY_STRLEN);
} }
bool GCMemcard::GetDEntry(u8 index, DEntry& dest) const bool GCMemcard::GetDEntry(u8 index, DEntry& dest) const
@ -888,7 +890,7 @@ u32 GCMemcard::ImportGciInternal(File::IOFile&& gci, const std::string& inputFil
for (unsigned int i = 0; i < size; ++i) for (unsigned int i = 0; i < size; ++i)
{ {
GCMBlock b; GCMBlock b;
gci.ReadBytes(b.m_block, BLOCK_SIZE); gci.ReadBytes(b.m_block.data(), b.m_block.size());
saveData.push_back(b); saveData.push_back(b);
} }
u32 ret; u32 ret;
@ -909,7 +911,7 @@ u32 GCMemcard::ImportGciInternal(File::IOFile&& gci, const std::string& inputFil
for (int i = 0; i < fileBlocks; ++i) for (int i = 0; i < fileBlocks; ++i)
{ {
if (!gci2.WriteBytes(saveData[i].m_block, BLOCK_SIZE)) if (!gci2.WriteBytes(saveData[i].m_block.data(), saveData[i].m_block.size()))
completeWrite = false; completeWrite = false;
} }
@ -1002,7 +1004,7 @@ u32 GCMemcard::ExportGci(u8 index, const std::string& fileName, const std::strin
gci.Seek(DENTRY_SIZE + offset, SEEK_SET); gci.Seek(DENTRY_SIZE + offset, SEEK_SET);
for (unsigned int i = 0; i < size; ++i) for (unsigned int i = 0; i < size; ++i)
{ {
gci.WriteBytes(saveData[i].m_block, BLOCK_SIZE); gci.WriteBytes(saveData[i].m_block.data(), saveData[i].m_block.size());
} }
if (gci.IsGood()) if (gci.IsGood())
@ -1097,14 +1099,14 @@ bool GCMemcard::ReadBannerRGBA8(u8 index, u32* buffer) const
if (bnrFormat & 1) if (bnrFormat & 1)
{ {
u8* pxdata = (u8*)(m_data_blocks[DataBlock].m_block + DataOffset); u8* pxdata = (u8*)(m_data_blocks[DataBlock].m_block.data() + DataOffset);
u16* paldata = (u16*)(m_data_blocks[DataBlock].m_block + DataOffset + pixels); u16* paldata = (u16*)(m_data_blocks[DataBlock].m_block.data() + DataOffset + pixels);
Common::DecodeCI8Image(buffer, pxdata, paldata, 96, 32); Common::DecodeCI8Image(buffer, pxdata, paldata, 96, 32);
} }
else else
{ {
u16* pxdata = (u16*)(m_data_blocks[DataBlock].m_block + DataOffset); u16* pxdata = (u16*)(m_data_blocks[DataBlock].m_block.data() + DataOffset);
Common::Decode5A3Image(buffer, pxdata, 96, 32); Common::Decode5A3Image(buffer, pxdata, 96, 32);
} }
@ -1140,7 +1142,7 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8* delays) const
return 0; return 0;
} }
u8* animData = (u8*)(m_data_blocks[DataBlock].m_block + DataOffset); u8* animData = (u8*)(m_data_blocks[DataBlock].m_block.data() + DataOffset);
switch (bnrFormat) switch (bnrFormat)
{ {

View File

@ -93,8 +93,8 @@ protected:
struct GCMBlock struct GCMBlock
{ {
GCMBlock() { Erase(); } GCMBlock() { Erase(); }
void Erase() { memset(m_block, 0xFF, BLOCK_SIZE); } void Erase() { memset(m_block.data(), 0xFF, m_block.size()); }
u8 m_block[BLOCK_SIZE]; std::array<u8, BLOCK_SIZE> m_block;
}; };
void calc_checksumsBE(const u16* buf, u32 length, u16* csum, u16* inv_csum); void calc_checksumsBE(const u16* buf, u32 length, u16* csum, u16* inv_csum);

View File

@ -517,7 +517,7 @@ inline s32 GCMemcardDirectory::SaveAreaRW(u32 block, bool writing)
} }
m_last_block = block; m_last_block = block;
m_last_block_address = m_saves[i].m_save_data[idx].m_block; m_last_block_address = m_saves[i].m_save_data[idx].m_block.data();
return m_last_block; return m_last_block;
} }
} }