2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/FacBinary.h>
|
2017-07-06 10:57:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
nx::FacBinary::FacBinary()
|
|
|
|
{}
|
|
|
|
|
|
|
|
nx::FacBinary::FacBinary(const FacBinary & other)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
copyFrom(other);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
nx::FacBinary::FacBinary(const u8 * bytes, size_t len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
importBinary(bytes, len);
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
bool nx::FacBinary::operator==(const FacBinary & other) const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
return isEqual(other);
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
bool nx::FacBinary::operator!=(const FacBinary & other) const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
return !isEqual(other);
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::operator=(const FacBinary & other)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
const u8 * nx::FacBinary::getBytes() const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
return mBinaryBlob.getBytes();
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
size_t nx::FacBinary::getSize() const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
return mBinaryBlob.getSize();
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::exportBinary()
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
FacHeader::setContentOwnerIdSize(mContentOwnerIdList.getSize() * sizeof(u32));
|
|
|
|
FacHeader::setSaveDataOwnerIdSize(mSaveDataOwnerIdList.getSize() * sizeof(u32));
|
|
|
|
FacHeader::exportBinary();
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
mBinaryBlob.alloc(getFacSize());
|
|
|
|
memcpy(mBinaryBlob.getBytes(), FacHeader::getBytes(), FacHeader::getSize());
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
u32* rawContentOwnerIds = (u32*)(mBinaryBlob.getBytes() + FacHeader::getContentOwnerIdOffset());
|
|
|
|
for (size_t i = 0; i < mContentOwnerIdList.getSize(); i++)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
rawContentOwnerIds[i] = le_word(mContentOwnerIdList[i]);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
2017-07-17 08:21:39 +00:00
|
|
|
|
|
|
|
u32* rawSaveDataOwnerIds = (u32*)(mBinaryBlob.getBytes() + FacHeader::getSaveDataOwnerIdOffset());
|
|
|
|
for (size_t i = 0; i < mSaveDataOwnerIdList.getSize(); i++)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
rawSaveDataOwnerIds[i] = le_word(mSaveDataOwnerIdList[i]);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::importBinary(const u8 * bytes, size_t len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
clear();
|
|
|
|
FacHeader::importBinary(bytes, len);
|
|
|
|
if (FacHeader::getFacSize() > len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "FAC binary too small");
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
mBinaryBlob.alloc(FacHeader::getFacSize());
|
2017-07-06 10:57:33 +00:00
|
|
|
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
u32* rawContentOwnerIds = (u32*)(mBinaryBlob.getBytes() + FacHeader::getContentOwnerIdOffset());
|
|
|
|
size_t rawContentOwnerIdNum = FacHeader::getContentOwnerIdSize() / sizeof(u32);
|
2017-07-06 10:57:33 +00:00
|
|
|
for (size_t i = 0; i < rawContentOwnerIdNum; i++)
|
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
mContentOwnerIdList.addElement(le_word(rawContentOwnerIds[i]));
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
u32* rawSaveDataOwnerIds = (u32*)(mBinaryBlob.getBytes() + FacHeader::getSaveDataOwnerIdOffset());
|
|
|
|
size_t rawSaveDataOwnerIdNum = FacHeader::getSaveDataOwnerIdSize() / sizeof(u32);
|
2017-07-06 10:57:33 +00:00
|
|
|
for (size_t i = 0; i < rawSaveDataOwnerIdNum; i++)
|
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
mSaveDataOwnerIdList.addElement(le_word(rawSaveDataOwnerIds[i]));
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
bool nx::FacBinary::isEqual(const FacBinary & other) const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
return (FacHeader::operator==(other)) \
|
|
|
|
&& (mContentOwnerIdList == other.mContentOwnerIdList) \
|
|
|
|
&& (mSaveDataOwnerIdList == other.mSaveDataOwnerIdList);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::copyFrom(const FacBinary & other)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
if (other.getSize())
|
|
|
|
{
|
|
|
|
importBinary(other.getBytes(), other.getSize());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FacHeader::operator=(other);
|
|
|
|
mContentOwnerIdList = other.mContentOwnerIdList;
|
|
|
|
mSaveDataOwnerIdList = other.mSaveDataOwnerIdList;
|
|
|
|
}
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::clear()
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
FacHeader::clear();
|
|
|
|
mContentOwnerIdList.clear();
|
|
|
|
mSaveDataOwnerIdList.clear();
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
const fnd::List<u32>& nx::FacBinary::getContentOwnerIdList() const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
return mContentOwnerIdList;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::setContentOwnerIdList(const fnd::List<u32>& list)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
mContentOwnerIdList = list;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
const fnd::List<u32>& nx::FacBinary::getSaveDataOwnerIdList() const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
return mSaveDataOwnerIdList;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::setSaveDataOwnerIdList(const fnd::List<u32>& list)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
mSaveDataOwnerIdList = list;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|