Added CMakeLists.txt

This commit is contained in:
Jack Andersen 2015-07-06 17:22:19 -10:00
parent 179013df15
commit dea4eda76d
9 changed files with 296 additions and 1 deletions

15
CMakeLists.txt Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.0)
project(NODLib)
if (NOT TARGET LogVisor)
add_subdirectory(LogVisor)
endif()
include_directories(include ${LOG_VISOR_INCLUDE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
file(GLOB NOD_HEADERS include/NOD/*.hpp)
add_subdirectory(lib)
add_subdirectory(driver)
install(DIRECTORY include/NOD DESTINATION include/NOD)
set(NOD_LIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "NODLib include dir" FORCE)

@ -1 +1 @@
Subproject commit c3dc632dd0f2f750697ccd6ee10898b4f45fb502 Subproject commit 4416d51c461c6d6c21ecf6c91c7a1c31210517d2

7
driver/CMakeLists.txt Normal file
View File

@ -0,0 +1,7 @@
add_executable(nodtool
main.cpp)
target_link_libraries(nodtool NOD LogVisor)
if (NOT WIN32)
target_link_libraries(nodtool pthread)
endif()

View File

@ -18,6 +18,7 @@ public:
{ {
virtual uint64_t read(void* buf, uint64_t length)=0; virtual uint64_t read(void* buf, uint64_t length)=0;
virtual void seek(int64_t offset, int whence=SEEK_SET)=0; virtual void seek(int64_t offset, int whence=SEEK_SET)=0;
virtual uint64_t position() const=0;
}; };
virtual std::unique_ptr<IReadStream> beginReadStream(uint64_t offset=0) const=0; virtual std::unique_ptr<IReadStream> beginReadStream(uint64_t offset=0) const=0;
@ -31,14 +32,269 @@ public:
struct IPartReadStream struct IPartReadStream
{ {
virtual void seek(int64_t offset, int whence=SEEK_SET)=0; virtual void seek(int64_t offset, int whence=SEEK_SET)=0;
virtual uint64_t position() const=0;
virtual uint64_t read(void* buf, uint64_t length)=0; virtual uint64_t read(void* buf, uint64_t length)=0;
}; };
struct IPartWriteStream struct IPartWriteStream
{ {
virtual void seek(int64_t offset, int whence=SEEK_SET)=0;
virtual uint64_t position() const=0;
virtual uint64_t write(void* buf, uint64_t length)=0; virtual uint64_t write(void* buf, uint64_t length)=0;
}; };
#if NOD_ATHENA
#include <Athena/IStreamReader.hpp>
#include <Athena/IStreamWriter.hpp>
class AthenaPartReadStream : public Athena::io::IStreamReader
{
std::unique_ptr<IPartReadStream> m_rs;
Athena::Endian m_endian;
public:
AthenaPartReadStream(std::unique_ptr<IPartReadStream>&& rs) : m_rs(std::move(rs)) {}
inline void setEndian(Athena::Endian endian) {m_endian = endian;}
inline Athena::Endian endian() const {return m_endian;}
inline bool isBigEndian() const {return m_endian == Athena::BigEndian;}
inline bool isLittleEndian()const {return m_endian == Athena::LittleEndian;}
inline bool isOpen() const {return true;}
inline void seek(atInt64 off, Athena::SeekOrigin origin)
{
if (origin == Athena::Begin)
m_rs->seek(off, SEEK_SET);
else if (origin == Athena::Current)
m_rs->seek(off, SEEK_CUR);
}
inline void seekAlign32() {AthenaPartReadStream::seek(ROUND_UP_32(m_rs->position()), Athena::Begin);}
inline bool atEnd() const {return false;}
inline atUint64 position() const {return m_rs->position();}
inline atUint64 length() const {return 0;}
inline void seekBit(int) {}
inline bool readBit() {return false;}
inline atUint8 readUByte() {atUint8 val; m_rs->read(&val, 1); return val;}
inline atInt8 readByte() {return AthenaPartReadStream::readUByte();}
inline atUint8* readUBytes(atUint64 sz) {atUint8* buf = new atUint8[sz]; m_rs->read(buf, sz); return buf;}
inline atInt8* readBytes(atUint64 sz) {return (atInt8*)AthenaPartReadStream::readUBytes(sz);}
inline atUint64 readUBytesToBuf(void* buf, atUint64 sz) {m_rs->read(buf, sz); return sz;}
inline atUint64 readBytesToBuf(void* buf, atUint64 sz) {return AthenaPartReadStream::readUBytesToBuf(buf, sz);}
inline atUint16 readUint16()
{atUint16 val; m_rs->read(&val, 2); return (m_endian == Athena::BigEndian) ? Athena::utility::BigUint16(val) : Athena::utility::LittleUint16(val);}
inline atInt16 readInt16() {return AthenaPartReadStream::readUint16();}
inline atUint32 readUint32()
{atUint32 val; m_rs->read(&val, 4); return (m_endian == Athena::BigEndian) ? Athena::utility::BigUint32(val) : Athena::utility::LittleUint32(val);}
inline atInt32 readInt32() {return AthenaPartReadStream::readUint32();}
inline atUint64 readUint64()
{atUint64 val; m_rs->read(&val, 8); return (m_endian == Athena::BigEndian) ? Athena::utility::BigUint64(val) : Athena::utility::LittleUint64(val);}
inline atInt64 readInt64() {return AthenaPartReadStream::readUint64();}
inline double readDouble()
{double val; m_rs->read(&val, 8); return (m_endian == Athena::BigEndian) ? Athena::utility::BigDouble(val) : Athena::utility::LittleDouble(val);}
inline float readFloat()
{float val; m_rs->read(&val, 4); return (m_endian == Athena::BigEndian) ? Athena::utility::BigFloat(val) : Athena::utility::LittleFloat(val);}
inline bool readBool() {bool val; m_rs->read(&val, 1); return val;}
inline atVec3f readVec3f()
{
atVec3f val = {};
m_rs->read(&val, 12);
if (m_endian == Athena::BigEndian)
{
Athena::utility::BigFloat(val.vec[0]);
Athena::utility::BigFloat(val.vec[1]);
Athena::utility::BigFloat(val.vec[2]);
}
else
{
Athena::utility::LittleFloat(val.vec[0]);
Athena::utility::LittleFloat(val.vec[1]);
Athena::utility::LittleFloat(val.vec[2]);
}
return val;
}
inline atVec4f readVec4f()
{
atVec4f val;
m_rs->read(&val, 16);
if (m_endian == Athena::BigEndian)
{
Athena::utility::BigFloat(val.vec[0]);
Athena::utility::BigFloat(val.vec[1]);
Athena::utility::BigFloat(val.vec[2]);
Athena::utility::BigFloat(val.vec[3]);
}
else
{
Athena::utility::LittleFloat(val.vec[0]);
Athena::utility::LittleFloat(val.vec[1]);
Athena::utility::LittleFloat(val.vec[2]);
Athena::utility::LittleFloat(val.vec[3]);
}
return val;
}
inline std::string readUnicode(atInt32 = -1)
{return std::string();}
inline std::string readString(atInt32 len = -1)
{
if (len < 0)
{
std::string result;
for (;;)
{
char aChar;
m_rs->read(&aChar, 1);
if (!aChar)
break;
result += aChar;
}
return result;
}
atUint8* chars = AthenaPartReadStream::readUBytes(len);
std::string result((char*)chars, len);
delete[] chars;
return result;
}
inline std::wstring readWString(atInt32 len = -1)
{
if (len < 0)
{
std::wstring result;
for (;;)
{
atUint16 aChar = AthenaPartReadStream::readUint16();
if (!aChar)
break;
result += aChar;
}
return result;
}
std::wstring result;
result.reserve(len);
for (atInt32 c=0 ; c<len ; ++c)
{
atUint16 aChar = AthenaPartReadStream::readUint16();
result += aChar;
}
return result;
}
};
class AthenaPartWriteStream : public Athena::io::IStreamWriter
{
std::unique_ptr<IPartWriteStream> m_ws;
Athena::Endian m_endian;
public:
AthenaPartWriteStream(std::unique_ptr<IPartWriteStream>&& ws) : m_ws(std::move(ws)) {}
inline void setEndian(Athena::Endian endian) {m_endian = endian;}
inline Athena::Endian endian() const {return m_endian;}
inline bool isBigEndian() const {return m_endian == Athena::BigEndian;}
inline bool isLittleEndian()const {return m_endian == Athena::LittleEndian;}
inline bool isOpen() const {return true;}
inline void seek(atInt64 off, Athena::SeekOrigin origin)
{
if (origin == Athena::Begin)
m_ws->seek(off, SEEK_SET);
else if (origin == Athena::Current)
m_ws->seek(off, SEEK_CUR);
}
inline void seekAlign32() {AthenaPartWriteStream::seek(ROUND_UP_32(m_ws->position()), Athena::Begin);}
inline bool atEnd() const {return false;}
inline atUint64 position() const {return m_ws->position();}
inline atUint64 length() const {return 0;}
inline void seekBit(int) {}
inline void writeBit(bool) {}
inline void writeUByte(atUint8 val) {m_ws->write(&val, 1);}
inline void writeByte(atInt8 val) {m_ws->write(&val, 1);}
inline void writeUBytes(const atUint8* buf, atUint64 len) {m_ws->write((void*)buf, len);}
inline void writeBytes(const atInt8* buf, atUint64 len) {m_ws->write((void*)buf, len);}
inline void writeUint16(atUint16 val)
{if (m_endian == Athena::BigEndian) Athena::utility::BigUint16(val); else Athena::utility::LittleUint16(val); m_ws->write(&val, 2);}
inline void writeInt16(atInt16 val) {AthenaPartWriteStream::writeUint16(val);}
inline void writeUint32(atUint32 val)
{if (m_endian == Athena::BigEndian) Athena::utility::BigUint32(val); else Athena::utility::LittleUint32(val); m_ws->write(&val, 4);}
inline void writeInt32(atInt32 val) {AthenaPartWriteStream::writeUint32(val);}
inline void writeUint64(atUint64 val)
{if (m_endian == Athena::BigEndian) Athena::utility::BigUint64(val); else Athena::utility::LittleUint64(val); m_ws->write(&val, 8);}
inline void writeInt64(atInt64 val) {AthenaPartWriteStream::writeUint64(val);}
inline void writeDouble(double val)
{if (m_endian == Athena::BigEndian) Athena::utility::BigDouble(val); else Athena::utility::LittleDouble(val); m_ws->write(&val, 8);}
inline void writeFloat(float val)
{if (m_endian == Athena::BigEndian) Athena::utility::BigFloat(val); else Athena::utility::LittleFloat(val); m_ws->write(&val, 4);}
inline void writeBool(bool val) {m_ws->write(&val, 1);}
inline void writeVec3f(atVec3f vec)
{
if (m_endian == Athena::BigEndian)
{
Athena::utility::BigFloat(vec.vec[0]);
Athena::utility::BigFloat(vec.vec[1]);
Athena::utility::BigFloat(vec.vec[2]);
}
else
{
Athena::utility::LittleFloat(vec.vec[0]);
Athena::utility::LittleFloat(vec.vec[1]);
Athena::utility::LittleFloat(vec.vec[2]);
}
m_ws->write(&vec, 12);
}
inline void writeVec4f(atVec4f vec)
{
if (m_endian == Athena::BigEndian)
{
Athena::utility::BigFloat(vec.vec[0]);
Athena::utility::BigFloat(vec.vec[1]);
Athena::utility::BigFloat(vec.vec[2]);
Athena::utility::BigFloat(vec.vec[3]);
}
else
{
Athena::utility::LittleFloat(vec.vec[0]);
Athena::utility::LittleFloat(vec.vec[1]);
Athena::utility::LittleFloat(vec.vec[2]);
Athena::utility::LittleFloat(vec.vec[3]);
}
m_ws->write(&vec, 16);
}
inline void writeString(const std::string& str, atInt32 len = -1)
{
if (len < 0)
m_ws->write((void*)str.c_str(), str.size() + 1);
else
m_ws->write((void*)str.c_str(), len);
}
inline void writeWString(const std::wstring& str, atInt32 len = -1)
{
if (len < 0)
{
for (atUint16 ch : str)
AthenaPartWriteStream::writeUint16(ch);
AthenaPartWriteStream::writeUint16(0);
}
else
{
for (atInt32 c=0 ; c<len ; ++c)
{
if (c >= (atInt32)str.size())
AthenaPartWriteStream::writeUint16(0);
else
AthenaPartWriteStream::writeUint16(str[c]);
}
}
}
inline void writeUnicode(const std::string&, atInt32 = -1) {}
inline void fill(atUint8 val, atUint64 len)
{
for (atUint64 b=0 ; b<len ; ++b)
AthenaPartWriteStream::writeUByte(val);
}
inline void fill(atInt8 val, atUint64 len)
{
for (atUint64 b=0 ; b<len ; ++b)
AthenaPartWriteStream::writeByte(val);
}
};
#endif
} }
#endif // __NOD_IDISC_IO__ #endif // __NOD_IDISC_IO__

12
lib/CMakeLists.txt Normal file
View File

@ -0,0 +1,12 @@
add_library(NOD
aes.cpp
DiscBase.cpp
DiscGCN.cpp
DiscIOISO.cpp
DiscIOWBFS.cpp
DiscWii.cpp
FileIOFILE.cpp
FileIOMEM.cpp
NOD.cpp
WideStringConvert.cpp
${NOD_HEADERS})

View File

@ -35,6 +35,7 @@ public:
{m_dio = m_parent.m_parent.getDiscIO().beginReadStream(offset);} {m_dio = m_parent.m_parent.getDiscIO().beginReadStream(offset);}
void seek(int64_t offset, int whence) void seek(int64_t offset, int whence)
{m_dio->seek(offset, whence);} {m_dio->seek(offset, whence);}
uint64_t position() const {return m_dio->position();}
uint64_t read(void* buf, uint64_t length) uint64_t read(void* buf, uint64_t length)
{return m_dio->read(buf, length);} {return m_dio->read(buf, length);}
}; };

View File

@ -23,6 +23,8 @@ public:
public: public:
uint64_t read(void* buf, uint64_t length) uint64_t read(void* buf, uint64_t length)
{return fread(buf, 1, length, fp);} {return fread(buf, 1, length, fp);}
uint64_t position() const
{return ftello(fp);}
void seek(int64_t offset, int whence) void seek(int64_t offset, int whence)
{fseeko(fp, offset, whence);} {fseeko(fp, offset, whence);}
}; };

View File

@ -265,6 +265,7 @@ public:
m_offset += length; m_offset += length;
return length; return length;
} }
uint64_t position() const {return m_offset;}
void seek(int64_t offset, int whence) void seek(int64_t offset, int whence)
{ {
if (whence == SEEK_SET) if (whence == SEEK_SET)

View File

@ -294,6 +294,7 @@ public:
m_curBlock = block; m_curBlock = block;
} }
} }
uint64_t position() const {return m_offset;}
uint64_t read(void* buf, uint64_t length) uint64_t read(void* buf, uint64_t length)
{ {
size_t block = m_offset / 0x7c00; size_t block = m_offset / 0x7c00;