2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/FacBinary.h>
|
2018-06-24 15:56:55 +00:00
|
|
|
#include <nx/FacHeader.h>
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
nx::FacBinary::FacBinary()
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
clear();
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
nx::FacBinary::FacBinary(const FacBinary & other)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
*this = other;
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 08:21:39 +00:00
|
|
|
void nx::FacBinary::operator=(const FacBinary & other)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
if (other.getBytes().size())
|
|
|
|
{
|
|
|
|
fromBytes(other.getBytes().data(), other.getBytes().size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clear();
|
2018-06-24 15:56:55 +00:00
|
|
|
mFsaRights = other.mFsaRights;
|
2018-06-24 08:18:54 +00:00
|
|
|
mContentOwnerIdList = other.mContentOwnerIdList;
|
|
|
|
mSaveDataOwnerIdList = other.mSaveDataOwnerIdList;
|
|
|
|
}
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
bool nx::FacBinary::operator==(const FacBinary & other) const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 15:56:55 +00:00
|
|
|
return (mFsaRights == other.mFsaRights) \
|
2018-06-24 08:18:54 +00:00
|
|
|
&& (mContentOwnerIdList == other.mContentOwnerIdList) \
|
|
|
|
&& (mSaveDataOwnerIdList == other.mSaveDataOwnerIdList);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
bool nx::FacBinary::operator!=(const FacBinary & other) const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return !(*this == other);
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::FacBinary::toBytes()
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 15:56:55 +00:00
|
|
|
FacHeader hdr;
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2018-06-25 12:13:52 +00:00
|
|
|
FacHeader::sSection content_id_list_pos, savedata_owner_id_list_pos;
|
|
|
|
|
|
|
|
content_id_list_pos.size = mContentOwnerIdList.size() * sizeof(uint32_t);
|
|
|
|
content_id_list_pos.offset = align(sizeof(sFacHeader), 4);
|
|
|
|
savedata_owner_id_list_pos.size = mSaveDataOwnerIdList.size() * sizeof(uint32_t);
|
|
|
|
savedata_owner_id_list_pos.offset = content_id_list_pos.offset + align(content_id_list_pos.size, 4);
|
|
|
|
|
2018-06-24 15:56:55 +00:00
|
|
|
hdr.setFormatVersion(fac::kFacFormatVersion);
|
|
|
|
hdr.setFsaRightsList(mFsaRights);
|
2018-06-25 12:13:52 +00:00
|
|
|
hdr.setContentOwnerIdPos(content_id_list_pos);
|
|
|
|
hdr.setSaveDataOwnerIdPos(savedata_owner_id_list_pos);
|
2018-06-24 15:56:55 +00:00
|
|
|
hdr.toBytes();
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2018-06-24 15:56:55 +00:00
|
|
|
mRawBinary.alloc(hdr.getFacSize());
|
|
|
|
memcpy(mRawBinary.data(), hdr.getBytes().data(), hdr.getBytes().size());
|
|
|
|
|
2018-06-25 12:13:52 +00:00
|
|
|
uint32_t* rawContentOwnerIds = (uint32_t*)(mRawBinary.data() + content_id_list_pos.offset);
|
2018-06-24 08:18:54 +00:00
|
|
|
for (size_t i = 0; i < mContentOwnerIdList.size(); 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
|
|
|
|
2018-06-25 12:13:52 +00:00
|
|
|
uint32_t* rawSaveDataOwnerIds = (uint32_t*)(mRawBinary.data() + savedata_owner_id_list_pos.offset);
|
2018-06-24 08:18:54 +00:00
|
|
|
for (size_t i = 0; i < mSaveDataOwnerIdList.size(); 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
void nx::FacBinary::fromBytes(const byte_t* data, size_t len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2017-07-17 08:21:39 +00:00
|
|
|
clear();
|
2018-06-24 15:56:55 +00:00
|
|
|
|
|
|
|
FacHeader hdr;
|
|
|
|
hdr.fromBytes(data, len);
|
|
|
|
|
|
|
|
mFsaRights = hdr.getFsaRightsList();
|
|
|
|
|
|
|
|
if (hdr.getFacSize() > len)
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "FAC binary too small");
|
|
|
|
}
|
|
|
|
|
2018-06-24 15:56:55 +00:00
|
|
|
mRawBinary.alloc(hdr.getFacSize());
|
2018-06-24 08:18:54 +00:00
|
|
|
memcpy(mRawBinary.data(), data, mRawBinary.size());
|
2017-07-06 10:57:33 +00:00
|
|
|
|
2018-06-24 15:56:55 +00:00
|
|
|
uint32_t* rawContentOwnerIds = (uint32_t*)(mRawBinary.data() + hdr.getContentOwnerIdPos().offset);
|
|
|
|
size_t rawContentOwnerIdNum = hdr.getContentOwnerIdPos().size / sizeof(uint32_t);
|
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
|
|
|
}
|
|
|
|
|
2018-06-24 15:56:55 +00:00
|
|
|
uint32_t* rawSaveDataOwnerIds = (uint32_t*)(mRawBinary.data() + hdr.getSaveDataOwnerIdPos().offset);
|
|
|
|
size_t rawSaveDataOwnerIdNum = hdr.getSaveDataOwnerIdPos().size / sizeof(uint32_t);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 08:18:54 +00:00
|
|
|
const fnd::Vec<byte_t>& nx::FacBinary::getBytes() const
|
2017-07-06 10:57:33 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return mRawBinary;
|
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
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.clear();
|
2017-07-17 08:21:39 +00:00
|
|
|
mContentOwnerIdList.clear();
|
|
|
|
mSaveDataOwnerIdList.clear();
|
2017-07-06 10:57:33 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:56:55 +00:00
|
|
|
const fnd::List<nx::fac::FsAccessFlag>& nx::FacBinary::getFsaRightsList() const
|
|
|
|
{
|
|
|
|
return mFsaRights;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::FacBinary::setFsaRightsList(const fnd::List<fac::FsAccessFlag>& list)
|
|
|
|
{
|
|
|
|
mFsaRights.clear();
|
|
|
|
for (size_t i = 0; i < list.size(); i++)
|
|
|
|
{
|
|
|
|
mFsaRights.hasElement(list[i]) ? mFsaRights.addElement(list[i]) : throw fnd::Exception(kModuleName, "FSA right already exists");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const fnd::List<uint32_t>& 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
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void nx::FacBinary::setContentOwnerIdList(const fnd::List<uint32_t>& 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
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const fnd::List<uint32_t>& 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
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void nx::FacBinary::setSaveDataOwnerIdList(const fnd::List<uint32_t>& 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
|
|
|
}
|