[nx] Updated FacHeader/FacBinary

This commit is contained in:
jakcron 2018-06-25 20:13:52 +08:00
parent c4c2610417
commit 19bd03630d
3 changed files with 17 additions and 19 deletions

View file

@ -56,10 +56,10 @@ namespace nx
void setFsaRightsList(const fnd::List<fac::FsAccessFlag>& list);
const sSection& getContentOwnerIdPos() const;
void setContentOwnerIdSize(size_t size);
void setContentOwnerIdPos(const sSection& pos);
const sSection& getSaveDataOwnerIdPos() const;;
void setSaveDataOwnerIdSize(size_t size);
void setSaveDataOwnerIdPos(const sSection& pos);
private:
const std::string kModuleName = "FAC_HEADER";
@ -72,8 +72,6 @@ namespace nx
fnd::List<fac::FsAccessFlag> mFsaRights;
sSection mContentOwnerIdPos;
sSection mSaveDataOwnerIdPos;
void calculateOffsets();
};
}

View file

@ -42,22 +42,29 @@ void nx::FacBinary::toBytes()
{
FacHeader hdr;
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);
hdr.setFormatVersion(fac::kFacFormatVersion);
hdr.setFsaRightsList(mFsaRights);
hdr.setContentOwnerIdSize(mContentOwnerIdList.size() * sizeof(uint32_t));
hdr.setSaveDataOwnerIdSize(mSaveDataOwnerIdList.size() * sizeof(uint32_t));
hdr.setContentOwnerIdPos(content_id_list_pos);
hdr.setSaveDataOwnerIdPos(savedata_owner_id_list_pos);
hdr.toBytes();
mRawBinary.alloc(hdr.getFacSize());
memcpy(mRawBinary.data(), hdr.getBytes().data(), hdr.getBytes().size());
uint32_t* rawContentOwnerIds = (uint32_t*)(mRawBinary.data() + hdr.getContentOwnerIdPos().offset);
uint32_t* rawContentOwnerIds = (uint32_t*)(mRawBinary.data() + content_id_list_pos.offset);
for (size_t i = 0; i < mContentOwnerIdList.size(); i++)
{
rawContentOwnerIds[i] = le_word(mContentOwnerIdList[i]);
}
uint32_t* rawSaveDataOwnerIds = (uint32_t*)(mRawBinary.data() + hdr.getSaveDataOwnerIdPos().offset);
uint32_t* rawSaveDataOwnerIds = (uint32_t*)(mRawBinary.data() + savedata_owner_id_list_pos.offset);
for (size_t i = 0; i < mSaveDataOwnerIdList.size(); i++)
{
rawSaveDataOwnerIds[i] = le_word(mSaveDataOwnerIdList[i]);

View file

@ -61,7 +61,6 @@ void nx::FacHeader::toBytes()
}
hdr->fac_flags = (flag);
calculateOffsets();
hdr->content_owner_ids.start = (uint32_t)(mContentOwnerIdPos.offset);
hdr->content_owner_ids.end = (uint32_t)(mContentOwnerIdPos.offset + mContentOwnerIdPos.size);
hdr->save_data_owner_ids.start = (uint32_t)(mSaveDataOwnerIdPos.offset);
@ -151,9 +150,9 @@ const nx::FacHeader::sSection& nx::FacHeader::getContentOwnerIdPos() const
return mContentOwnerIdPos;
}
void nx::FacHeader::setContentOwnerIdSize(size_t size)
void nx::FacHeader::setContentOwnerIdPos(const sSection& pos)
{
mContentOwnerIdPos.size = size;
mContentOwnerIdPos = pos;
}
const nx::FacHeader::sSection& nx::FacHeader::getSaveDataOwnerIdPos() const
@ -161,13 +160,7 @@ const nx::FacHeader::sSection& nx::FacHeader::getSaveDataOwnerIdPos() const
return mSaveDataOwnerIdPos;
}
void nx::FacHeader::setSaveDataOwnerIdSize(size_t size)
void nx::FacHeader::setSaveDataOwnerIdPos(const sSection& pos)
{
mSaveDataOwnerIdPos.size = size;
}
void nx::FacHeader::calculateOffsets()
{
mContentOwnerIdPos.offset = align(sizeof(sFacHeader), 4);
mSaveDataOwnerIdPos.offset = mContentOwnerIdPos.offset + align(mContentOwnerIdPos.size, 4);
mSaveDataOwnerIdPos = pos;
}