Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CFileSystemGCWii::Read32 #2361

Merged
merged 1 commit into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 18 additions & 25 deletions Source/Core/DiscIO/FileSystemGCWii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ bool CFileSystemGCWii::ExportFile(const std::string& _rFullPath, const std::stri

bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const
{
u32 AppSize = Read32(0x2440 + 0x14);// apploader size
AppSize += Read32(0x2440 + 0x18); // + trailer size
AppSize += 0x20; // + header size
u32 AppSize = m_rVolume->Read32(0x2440 + 0x14, m_Wii); // apploader size
AppSize += m_rVolume->Read32(0x2440 + 0x18, m_Wii); // + trailer size
AppSize += 0x20; // + header size
DEBUG_LOG(DISCIO,"AppSize -> %x", AppSize);

std::vector<u8> buffer(AppSize);
Expand All @@ -147,23 +147,23 @@ bool CFileSystemGCWii::ExportApploader(const std::string& _rExportFolder) const

u32 CFileSystemGCWii::GetBootDOLSize() const
{
u32 DolOffset = Read32(0x420) << GetOffsetShift();
u32 DolOffset = m_rVolume->Read32(0x420, m_Wii) << GetOffsetShift();
u32 DolSize = 0, offset = 0, size = 0;

// Iterate through the 7 code segments
for (u8 i = 0; i < 7; i++)
{
offset = Read32(DolOffset + 0x00 + i * 4);
size = Read32(DolOffset + 0x90 + i * 4);
offset = m_rVolume->Read32(DolOffset + 0x00 + i * 4, m_Wii);
size = m_rVolume->Read32(DolOffset + 0x90 + i * 4, m_Wii);
if (offset + size > DolSize)
DolSize = offset + size;
}

// Iterate through the 11 data segments
for (u8 i = 0; i < 11; i++)
{
offset = Read32(DolOffset + 0x1c + i * 4);
size = Read32(DolOffset + 0xac + i * 4);
offset = m_rVolume->Read32(DolOffset + 0x1c + i * 4, m_Wii);
size = m_rVolume->Read32(DolOffset + 0xac + i * 4, m_Wii);
if (offset + size > DolSize)
DolSize = offset + size;
}
Expand All @@ -172,13 +172,13 @@ u32 CFileSystemGCWii::GetBootDOLSize() const

bool CFileSystemGCWii::GetBootDOL(u8* &buffer, u32 DolSize) const
{
u32 DolOffset = Read32(0x420) << GetOffsetShift();
u32 DolOffset = m_rVolume->Read32(0x420, m_Wii) << GetOffsetShift();
return m_rVolume->Read(DolOffset, DolSize, buffer, m_Wii);
}

bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
{
u32 DolOffset = Read32(0x420) << GetOffsetShift();
u32 DolOffset = m_rVolume->Read32(0x420, m_Wii) << GetOffsetShift();
u32 DolSize = GetBootDOLSize();

std::vector<u8> buffer(DolSize);
Expand All @@ -197,13 +197,6 @@ bool CFileSystemGCWii::ExportDOL(const std::string& _rExportFolder) const
return false;
}

u32 CFileSystemGCWii::Read32(u64 _Offset) const
{
u32 Temp = 0;
m_rVolume->Read(_Offset, 4, (u8*)&Temp, m_Wii);
return Common::swap32(Temp);
}

std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const
{
std::string data(255, 0x00);
Expand Down Expand Up @@ -245,12 +238,12 @@ const SFileInfo* CFileSystemGCWii::FindFileInfo(const std::string& _rFullPath)

bool CFileSystemGCWii::DetectFileSystem()
{
if (Read32(0x18) == 0x5D1C9EA3)
if (m_rVolume->Read32(0x18, false) == 0x5D1C9EA3)
{
m_Wii = true;
return true;
}
else if (Read32(0x1c) == 0xC2339F3D)
else if (m_rVolume->Read32(0x1c, false) == 0xC2339F3D)
{
m_Wii = false;
return true;
Expand All @@ -265,17 +258,17 @@ void CFileSystemGCWii::InitFileSystem()
u32 const shift = GetOffsetShift();

// read the whole FST
u64 FSTOffset = static_cast<u64>(Read32(0x424)) << shift;
u64 FSTOffset = static_cast<u64>(m_rVolume->Read32(0x424, m_Wii)) << shift;
// u32 FSTSize = Read32(0x428);
// u32 FSTMaxSize = Read32(0x42C);


// read all fileinfos
SFileInfo Root
{
Read32(FSTOffset + 0x0),
m_rVolume->Read32(FSTOffset + 0x0, m_Wii),
static_cast<u64>(FSTOffset + 0x4) << shift,
Read32(FSTOffset + 0x8)
m_rVolume->Read32(FSTOffset + 0x8, m_Wii)
};

if (!Root.IsDirectory())
Expand All @@ -289,9 +282,9 @@ void CFileSystemGCWii::InitFileSystem()
for (u32 i = 0; i < Root.m_FileSize; i++)
{
u64 const read_offset = FSTOffset + (i * 0xC);
u64 const name_offset = Read32(read_offset + 0x0);
u64 const offset = static_cast<u64>(Read32(read_offset + 0x4)) << shift;
u64 const size = Read32(read_offset + 0x8);
u64 const name_offset = m_rVolume->Read32(read_offset + 0x0, m_Wii);
u64 const offset = static_cast<u64>(m_rVolume->Read32(read_offset + 0x4, m_Wii)) << shift;
u64 const size = m_rVolume->Read32(read_offset + 0x8, m_Wii);
m_FileInfoVector.emplace_back(name_offset, offset, size);
NameTableOffset += 0xC;
}
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/DiscIO/FileSystemGCWii.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ class CFileSystemGCWii : public IFileSystem
bool m_Initialized;
bool m_Valid;
bool m_Wii;
std::vector<SFileInfo> m_FileInfoVector;

std::vector <SFileInfo> m_FileInfoVector;
u32 Read32(u64 _Offset) const;
std::string GetStringFromOffset(u64 _Offset) const;
const SFileInfo* FindFileInfo(const std::string& _rFullPath);
bool DetectFileSystem();
Expand Down