Skip to content
Permalink
Browse files

GCMemcard: Use BigEndianValue for DEntry.m_block_count.

  • Loading branch information...
AdmiralCurtiss committed Nov 18, 2018
1 parent 675a549 commit 8a920dac939300ef768198c95ab75d72c6ca9edf
@@ -522,7 +522,7 @@ u16 GCMemcard::DEntry_BlockCount(u8 index) const
if (!m_valid || index >= DIRLEN)
return 0xFFFF;

u16 blocks = BE16(CurrentDir->m_dir_entries[index].m_block_count);
u16 blocks = CurrentDir->m_dir_entries[index].m_block_count;
if (blocks > (u16)maxBlock)
return 0xFFFF;
return blocks;
@@ -660,7 +660,7 @@ u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlo
{
return OUTOFDIRENTRIES;
}
if (BE16(CurrentBat->m_free_blocks) < BE16(direntry.m_block_count))
if (BE16(CurrentBat->m_free_blocks) < direntry.m_block_count)
{
return OUTOFBLOCKS;
}
@@ -700,7 +700,7 @@ u32 GCMemcard::ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlo
PreviousDir = &dir;
}

int fileBlocks = BE16(direntry.m_block_count);
int fileBlocks = direntry.m_block_count;

FZEROGX_MakeSaveGameValid(hdr, direntry, saveBlocks);
PSO_MakeSaveGameValid(hdr, direntry, saveBlocks);
@@ -749,7 +749,7 @@ u32 GCMemcard::RemoveFile(u8 index) // index in the directory array
return DELETE_FAIL;

u16 startingblock = CurrentDir->m_dir_entries[index].m_first_block;
u16 numberofblocks = BE16(CurrentDir->m_dir_entries[index].m_block_count);
u16 numberofblocks = CurrentDir->m_dir_entries[index].m_block_count;

BlockAlloc UpdatedBat = *CurrentBat;
if (!UpdatedBat.ClearBlocks(startingblock, numberofblocks))
@@ -888,12 +888,12 @@ u32 GCMemcard::ImportGciInternal(File::IOFile&& gci, const std::string& inputFil

Gcs_SavConvert(tempDEntry, offset, length);

if (length != BE16(tempDEntry.m_block_count) * BLOCK_SIZE)
if (length != tempDEntry.m_block_count * BLOCK_SIZE)
return LENGTHFAIL;
if (gci.Tell() != offset + DENTRY_SIZE) // Verify correct file position
return OPENFAIL;

u32 size = BE16((tempDEntry.m_block_count));
u32 size = tempDEntry.m_block_count;
std::vector<GCMBlock> saveData;
saveData.reserve(size);

@@ -916,7 +916,7 @@ u32 GCMemcard::ImportGciInternal(File::IOFile&& gci, const std::string& inputFil

if (!gci2.WriteBytes(&tempDEntry, DENTRY_SIZE))
completeWrite = false;
int fileBlocks = BE16(tempDEntry.m_block_count);
int fileBlocks = tempDEntry.m_block_count;
gci2.Seek(DENTRY_SIZE, SEEK_SET);

for (int i = 0; i < fileBlocks; ++i)
@@ -1034,7 +1034,7 @@ void GCMemcard::Gcs_SavConvert(DEntry& tempDEntry, int saveType, int length)
// It is stored only within the corresponding GSV file.
// If the GCS file is added without using the GameSaves software,
// the value stored is always "1"
*(u16*)&tempDEntry.m_block_count = BE16(length / BLOCK_SIZE);
tempDEntry.m_block_count = length / BLOCK_SIZE;
}
break;
case SAV:
@@ -1065,7 +1065,10 @@ void GCMemcard::Gcs_SavConvert(DEntry& tempDEntry, int saveType, int length)
ByteSwap(&tmp[0], &tmp[1]);
memcpy(&tempDEntry.m_first_block, tmp.data(), 2);

ArrayByteSwap((tempDEntry.m_block_count));
memcpy(tmp.data(), &tempDEntry.m_block_count, 2);
ByteSwap(&tmp[0], &tmp[1]);
memcpy(&tempDEntry.m_block_count, tmp.data(), 2);

ArrayByteSwap((tempDEntry.m_unused_2));
ArrayByteSwap((tempDEntry.m_comments_address));
ArrayByteSwap(&(tempDEntry.m_comments_address[2]));
@@ -214,8 +214,9 @@ struct DEntry
//
u8 m_copy_counter; // 0x35 0x01 Copy counter (*2)
Common::BigEndianValue<u16>
m_first_block; // 0x36 0x02 Block no of first block of file (0 == offset 0)
u8 m_block_count[2]; // 0x38 0x02 File-length (number of blocks in file)
m_first_block; // 0x36 0x02 Block no of first block of file (0 == offset 0)
Common::BigEndianValue<u16>
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)
@@ -58,7 +58,7 @@ int GCMemcardDirectory::LoadGCI(const std::string& file_name, bool current_game_
}
}

u16 num_blocks = BE16(gci.m_gci_header.m_block_count);
u16 num_blocks = gci.m_gci_header.m_block_count;
// largest number of free blocks on a memory card
// in reality, there are not likely any valid gci files > 251 blocks
if (num_blocks > 2043)
@@ -151,7 +151,7 @@ std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::st
if (std::find(loaded_saves.begin(), loaded_saves.end(), gci_filename) != loaded_saves.end())
continue;

const u16 num_blocks = BE16(gci.m_gci_header.m_block_count);
const u16 num_blocks = gci.m_gci_header.m_block_count;
// largest number of free blocks on a memory card
// in reality, there are not likely any valid gci files > 251 blocks
if (num_blocks > 2043)
@@ -500,7 +500,7 @@ inline s32 GCMemcardDirectory::SaveAreaRW(u32 block, bool writing)
{
if (!m_saves[i].LoadSaveBlocks())
{
int num_blocks = BE16(m_saves[i].m_gci_header.m_block_count);
int num_blocks = m_saves[i].m_gci_header.m_block_count;
while (num_blocks)
{
m_saves[i].m_save_data.emplace_back();
@@ -563,7 +563,7 @@ bool GCMemcardDirectory::SetUsedBlocks(int save_index)
}
}

u16 num_blocks = BE16(m_saves[save_index].m_gci_header.m_block_count);
u16 num_blocks = m_saves[save_index].m_gci_header.m_block_count;
u16 blocks_from_bat = (u16)m_saves[save_index].m_used_blocks.size();
if (blocks_from_bat != num_blocks)
{
@@ -703,7 +703,7 @@ bool GCIFile::LoadSaveBlocks()

INFO_LOG(EXPANSIONINTERFACE, "Reading savedata from disk for %s", m_filename.c_str());
save_file.Seek(DENTRY_SIZE, SEEK_SET);
u16 num_blocks = BE16(m_gci_header.m_block_count);
u16 num_blocks = m_gci_header.m_block_count;
m_save_data.resize(num_blocks);
if (!save_file.ReadBytes(m_save_data.data(), num_blocks * BLOCK_SIZE))
{

0 comments on commit 8a920da

Please sign in to comment.
You can’t perform that action at this time.