diff --git a/lib/libnx/include/nx/FacHeader.h b/lib/libnx/include/nx/FacHeader.h index 55bcc7d..08ab345 100644 --- a/lib/libnx/include/nx/FacHeader.h +++ b/lib/libnx/include/nx/FacHeader.h @@ -56,10 +56,10 @@ namespace nx void setFsaRightsList(const fnd::List& 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 mFsaRights; sSection mContentOwnerIdPos; sSection mSaveDataOwnerIdPos; - - void calculateOffsets(); }; } diff --git a/lib/libnx/source/FacBinary.cpp b/lib/libnx/source/FacBinary.cpp index f2f68db..cf391af 100644 --- a/lib/libnx/source/FacBinary.cpp +++ b/lib/libnx/source/FacBinary.cpp @@ -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]); diff --git a/lib/libnx/source/FacHeader.cpp b/lib/libnx/source/FacHeader.cpp index fc64958..d1a06b3 100644 --- a/lib/libnx/source/FacHeader.cpp +++ b/lib/libnx/source/FacHeader.cpp @@ -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; } \ No newline at end of file