DiscIO: Unify CBlobBigEndianReader

This commit is contained in:
JosJuice 2015-10-03 13:42:26 +02:00
parent c7e747d775
commit c01265db34
3 changed files with 31 additions and 43 deletions

View File

@ -17,6 +17,7 @@
#include <array>
#include <memory>
#include <string>
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
namespace DiscIO
@ -77,6 +78,36 @@ private:
std::array<u64, CACHE_SIZE> m_cache_tags;
};
class CBlobBigEndianReader
{
public:
CBlobBigEndianReader(IBlobReader& reader) : m_reader(reader) {}
u32 Read32(u64 offset) const
{
u32 temp;
m_reader.Read(offset, sizeof(u32), reinterpret_cast<u8*>(&temp));
return Common::swap32(temp);
}
u16 Read16(u64 offset) const
{
u16 temp;
m_reader.Read(offset, sizeof(u16), reinterpret_cast<u8*>(&temp));
return Common::swap16(temp);
}
u8 Read8(u64 offset) const
{
u8 temp;
m_reader.Read(offset, sizeof(u8), &temp);
return temp;
}
private:
IBlobReader& m_reader;
};
// Factory function - examines the path to choose the right type of IBlobReader, and returns one.
std::unique_ptr<IBlobReader> CreateBlobReader(const std::string& filename);

View File

@ -34,33 +34,6 @@ enum EDiscType
DISC_TYPE_WAD
};
class CBlobBigEndianReader
{
public:
CBlobBigEndianReader(IBlobReader& _rReader) : m_rReader(_rReader) {}
u32 Read32(u64 _Offset)
{
u32 Temp;
m_rReader.Read(_Offset, 4, (u8*)&Temp);
return Common::swap32(Temp);
}
u16 Read16(u64 _Offset)
{
u16 Temp;
m_rReader.Read(_Offset, 2, (u8*)&Temp);
return Common::swap16(Temp);
}
u8 Read8(u64 _Offset)
{
u8 Temp;
m_rReader.Read(_Offset, 1, &Temp);
return Temp;
}
private:
IBlobReader& m_rReader;
};
static const unsigned char s_master_key[16] = {
0xeb,0xe4,0x2a,0x22,0x5e,0x85,0x93,0xe4,
0x48,0xd9,0xc5,0x45,0x73,0x81,0xaa,0xf7

View File

@ -18,22 +18,6 @@
namespace DiscIO
{
class CBlobBigEndianReader
{
public:
CBlobBigEndianReader(DiscIO::IBlobReader& _rReader) : m_rReader(_rReader) {}
u32 Read32(u64 _Offset)
{
u32 Temp;
m_rReader.Read(_Offset, 4, (u8*)&Temp);
return(Common::swap32(Temp));
}
private:
DiscIO::IBlobReader& m_rReader;
};
WiiWAD::WiiWAD(const std::string& name)
{
std::unique_ptr<IBlobReader> reader(DiscIO::CreateBlobReader(name));