From 3a41af8a919f99ee76323a2d4a998185dd8e7033 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 19 Jan 2016 17:17:24 -1000 Subject: [PATCH] Initial image building --- include/NOD/DiscBase.hpp | 53 +++++++++++++++++++++++++++++++--------- include/NOD/DiscGCN.hpp | 4 ++- include/NOD/DiscWii.hpp | 4 ++- lib/CMakeLists.txt | 1 - lib/DiscGCN.cpp | 10 +++++++- lib/DiscWii.cpp | 8 ++++-- lib/FileIOMEM.cpp | 10 -------- 7 files changed, 62 insertions(+), 28 deletions(-) delete mode 100644 lib/FileIOMEM.cpp diff --git a/include/NOD/DiscBase.hpp b/include/NOD/DiscBase.hpp index 77c7d83..ff2f274 100644 --- a/include/NOD/DiscBase.hpp +++ b/include/NOD/DiscBase.hpp @@ -20,22 +20,42 @@ public: virtual ~DiscBase() {} struct Header { - char gameID[6]; - char discNum; - char discVersion; - char audioStreaming; - char streamBufSz; - char unk[14]; - uint32_t wiiMagic; - uint32_t gcnMagic; - char gameTitle[64]; + char m_gameID[6]; + char m_discNum; + char m_discVersion; + char m_audioStreaming; + char m_streamBufSz; + char m_unk[14]; + uint32_t m_wiiMagic; + uint32_t m_gcnMagic; + char m_gameTitle[64]; Header(IDiscIO& dio) { std::unique_ptr s = dio.beginReadStream(0); s->read(this, sizeof(*this)); - wiiMagic = SBig(wiiMagic); - gcnMagic = SBig(gcnMagic); + m_wiiMagic = SBig(m_wiiMagic); + m_gcnMagic = SBig(m_gcnMagic); + } + + Header(const char gameID[6], const char* gameTitle, char discNum=0, char discVersion=0, + char audioStreaming=1, char streamBufSz=0) + { + memset(this, 0, sizeof(*this)); + memcpy(m_gameID, gameID, 6); + strncpy(m_gameTitle, gameTitle, 64); + m_discNum = discNum; + m_discVersion = discVersion; + m_audioStreaming = audioStreaming; + m_streamBufSz = streamBufSz; + m_gcnMagic = 0xC2339F3D; + } + + void write(IDiscIO::IWriteStream& ws) const + { + Header hs(*this); + hs.m_gcnMagic = SBig(hs.m_gcnMagic); + ws.write(&hs, sizeof(hs)); } }; @@ -45,6 +65,14 @@ public: uint32_t offset; uint32_t length; public: + FSTNode(bool isDir, uint32_t nameOff, uint32_t off, uint32_t len) + { + typeAndNameOffset = nameOff & 0xffffff; + typeAndNameOffset |= isDir << 24; + typeAndNameOffset = SBig(typeAndNameOffset); + offset = SBig(off); + length = SBig(len); + } inline bool isDir() const {return ((SBig(typeAndNameOffset) >> 24) != 0);} inline uint32_t getNameOffset() const {return SBig(typeAndNameOffset) & 0xffffff;} inline uint32_t getOffset() const {return SBig(offset);} @@ -229,7 +257,6 @@ public: DiscBase(std::unique_ptr&& dio) : m_discIO(std::move(dio)), m_header(*m_discIO) {} - virtual bool commit()=0; inline const Header& getHeader() const {return m_header;} inline const IDiscIO& getDiscIO() const {return *m_discIO;} inline IPartition* getDataPartition() @@ -251,6 +278,8 @@ public: for (std::unique_ptr& part : m_partitions) part->extractToDirectory(path, ctx); } + virtual bool packFromDirectory(const SystemChar* dataPath, const SystemChar* updatePath, + const SystemChar* outPath, const char gameID[6], const char* gameTitle, bool korean=false)=0; }; using Partition = DiscBase::IPartition; diff --git a/include/NOD/DiscGCN.hpp b/include/NOD/DiscGCN.hpp index 690f35b..1ac1689 100644 --- a/include/NOD/DiscGCN.hpp +++ b/include/NOD/DiscGCN.hpp @@ -10,7 +10,9 @@ class DiscGCN : public DiscBase { public: DiscGCN(std::unique_ptr&& dio); - bool commit(); + bool packFromDirectory(const SystemChar* dataPath, const SystemChar* updatePath, + const SystemChar* outPath, const char gameID[6], const char* gameTitle, + bool korean=false); }; } diff --git a/include/NOD/DiscWii.hpp b/include/NOD/DiscWii.hpp index c6356f5..79d6ab7 100644 --- a/include/NOD/DiscWii.hpp +++ b/include/NOD/DiscWii.hpp @@ -10,7 +10,9 @@ class DiscWii : public DiscBase { public: DiscWii(std::unique_ptr&& dio); - bool commit(); + bool packFromDirectory(const SystemChar* dataPath, const SystemChar* updatePath, + const SystemChar* outPath, const char gameID[6], const char* gameTitle, + bool korean=false); }; } diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 696dbd4..fd50e7d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -9,7 +9,6 @@ add_library(NOD DiscIOWBFS.cpp DiscWii.cpp FileIOFILE.cpp - FileIOMEM.cpp NOD.cpp ${NOD_HEADERS}) if(NOT WIN32) diff --git a/lib/DiscGCN.cpp b/lib/DiscGCN.cpp index 26e990f..a45e84e 100644 --- a/lib/DiscGCN.cpp +++ b/lib/DiscGCN.cpp @@ -109,8 +109,16 @@ DiscGCN::DiscGCN(std::unique_ptr&& dio) m_partitions.emplace_back(new PartitionGCN(*this, IPartition::Kind::Data, 0)); } -bool DiscGCN::commit() +bool DiscGCN::packFromDirectory(const SystemChar* dataPath, const SystemChar* updatePath, + const SystemChar* outPath, const char gameID[6], const char* gameTitle, + bool korean) { + std::unique_ptr ws = m_discIO->beginWriteStream(0); + Header header(gameID, gameTitle); + header.write(*ws); + + ws = m_discIO->beginWriteStream(0x420); + return false; } diff --git a/lib/DiscWii.cpp b/lib/DiscWii.cpp index d871fda..d177210 100644 --- a/lib/DiscWii.cpp +++ b/lib/DiscWii.cpp @@ -6,7 +6,6 @@ namespace NOD { -/* Not much of a secret anymore I suppose */ static const uint8_t COMMON_KEYS[2][16] = { /* Normal */ @@ -391,8 +390,13 @@ DiscWii::DiscWii(std::unique_ptr&& dio) } } -bool DiscWii::commit() +bool DiscWii::packFromDirectory(const SystemChar* dataPath, const SystemChar* updatePath, + const SystemChar* outPath, const char gameID[6], const char* gameTitle, + bool korean) { + std::unique_ptr s = m_discIO->beginWriteStream(0x420); + + return false; } diff --git a/lib/FileIOMEM.cpp b/lib/FileIOMEM.cpp deleted file mode 100644 index ceff6f0..0000000 --- a/lib/FileIOMEM.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "NOD/IFileIO.hpp" - -namespace NOD -{ - -class FileIOMEM : public IFileIO -{ -}; - -}