diff --git a/CMakeLists.txt b/CMakeLists.txt index 937abdf..d8497ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,7 @@ unset(RDI_TARGETS_LIST) # Define src/headers files file(GLOB_RECURSE RDI_LIB_SOURCES ./src/*.cpp ./src/*.c) source_group("Source Files" FILES ${RDI_LIB_SOURCES}) -file(GLOB RSP_LIB_PUBLIC_HRDS ./include/*.h) +file(GLOB_RECURSE RSP_LIB_PUBLIC_HRDS ./include/*.hpp ./include/*.h) # Building instructions for RSP-Texture library @@ -148,24 +148,41 @@ endif() if(BUILD_TOOLS) # Add lib debug tool to buildchain - file(GLOB_RECURSE RDI_TOOLS_SOURCES ./tools/*.cpp ./tools/*.c) - source_group("Tools src files" FILES ${RDI_TOOLS_SOURCES}) + #file(GLOB_RECURSE RDI_TOOLS_SOURCES ./tools/*.cpp ./tools/*.c) + #source_group("Tools src files" FILES ${RDI_TOOLS_SOURCES}) - add_executable(rdi-debug-tools ${RDI_TOOLS_SOURCES}) + #add_executable(rdi-debug-tools ${RDI_TOOLS_SOURCES}) + add_executable(rdi-debug-tools ./tools/RDIDebug.cpp) set_property(TARGET rdi-debug-tools PROPERTY C_STANDARD 90) set_target_properties(rdi-debug-tools PROPERTIES OUTPUT_NAME "RDI-debug") list(APPEND RDI_TARGETS_LIST rdi-debug-tools) + add_executable(erso-debug-tools ./tools/ErsoDebug.cpp) + set_property(TARGET erso-debug-tools PROPERTY C_STANDARD 90) + set_target_properties(erso-debug-tools PROPERTIES OUTPUT_NAME "Erso-debug") + list(APPEND RDI_TARGETS_LIST erso-debug-tools) + + add_executable(krennic-debug-tools ./tools/KrennicDebug.cpp) + set_property(TARGET krennic-debug-tools PROPERTY C_STANDARD 90) + set_target_properties(krennic-debug-tools PROPERTIES OUTPUT_NAME "Krennic-debug") + list(APPEND RDI_TARGETS_LIST krennic-debug-tools) + if(MSVC) # msvc does not append 'lib' - do it here to have consistent name set_target_properties(rdi-debug-tools PROPERTIES IMPORT_PREFIX "lib") + set_target_properties(erso-debug-tools PROPERTIES IMPORT_PREFIX "lib") + set_target_properties(krennic-debug-tools PROPERTIES IMPORT_PREFIX "lib") endif() if(RDI_SHARED) target_link_libraries(rdi-debug-tools PRIVATE rdi-lib) + target_link_libraries(erso-debug-tools PRIVATE rdi-lib) + target_link_libraries(krennic-debug-tools PRIVATE rdi-lib) elseif(RDI_STATIC) target_link_libraries(rdi-debug-tools PRIVATE rdi-libstatic) + target_link_libraries(erso-debug-tools PRIVATE rdi-libstatic) + target_link_libraries(krennic-debug-tools PRIVATE rdi-libstatic) endif() endif() diff --git a/src/datfiles/GenericFile.h b/include/FileHandler/Generic.h similarity index 83% rename from src/datfiles/GenericFile.h rename to include/FileHandler/Generic.h index 1475e6d..bd2f152 100644 --- a/src/datfiles/GenericFile.h +++ b/include/FileHandler/Generic.h @@ -7,8 +7,8 @@ * */ +#include "../RDI_Datatypes.h" #include -#include "../DatEntry.h" #ifndef GENERICFILE_H_ @@ -16,9 +16,11 @@ namespace RDI { +class ErsoEntryFile; + class GenericFile { public: - GenericFile( FileEntry& hDat ); + GenericFile( ErsoEntryFile& hDat ); virtual ~GenericFile(); MEMFILE get() { return pMemLoc; } diff --git a/src/datfiles/HMT.h b/include/FileHandler/HMT.h similarity index 81% rename from src/datfiles/HMT.h rename to include/FileHandler/HMT.h index e4d108e..cc0e59c 100644 --- a/src/datfiles/HMT.h +++ b/include/FileHandler/HMT.h @@ -7,7 +7,7 @@ * */ -#include "GenericFile.h" +#include #ifndef HMT_H_ @@ -17,7 +17,7 @@ namespace RDI { class HMT : public GenericFile { public: - HMT( FileEntry& hDat ); + HMT( ErsoEntryFile& hDat ); virtual ~HMT(); }; diff --git a/include/RDI.h b/include/RDI.hpp similarity index 93% rename from include/RDI.h rename to include/RDI.hpp index cdb1d81..0399849 100644 --- a/include/RDI.h +++ b/include/RDI.hpp @@ -1,17 +1,19 @@ /** - * @file RDI.h - * @date 15/09/2022 + * @file RDI.hpp + * @date 24/09/2022 * @author JackCarterSmith * @copyright GPL-v3.0 * @brief Rogue Data Interface library main entry file. * */ +#include +#include #include "RDI_Datatypes.h" -#ifndef RDI_H_ -#define RDI_H_ +#ifndef RDI_HPP_ +#define RDI_HPP_ #if defined(_MSC_VER) @@ -81,4 +83,4 @@ namespace RDI { } -#endif /* RDI_H_ */ +#endif /* RDI_HPP_ */ diff --git a/src/DatEntry.cpp b/src/DatEntry.cpp deleted file mode 100644 index 354c21a..0000000 --- a/src/DatEntry.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file DatEntry.cpp - * @date 20/09/2022 - * @author JackCarterSmith - * @copyright GPL-v3.0 - * @brief Data file entry descriptor class. - * - */ - -#include "DatEntry.h" - - -namespace RDI { - -FileEntry::FileEntry( std::string name, DAT_FILE_FLAGS fFlags, unsigned int size, MEMFILE fPtr ) { - this->name = name; - this->size = size; - this->fFlags.raw = fFlags.raw; - this->fileMemPtr = fPtr; -} - -FileEntry::~FileEntry() {} - -/*std::string FileEntry::toString() { - -}*/ - - -DirectoryEntry::DirectoryEntry( std::string name ) { - this->name = name; - this->fFlags.raw = 0; - this->rootDir = true; - vSubFiles = new std::vector; -} - -DirectoryEntry::DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags ) { - this->name = name; - this->fFlags.raw = fFlags.raw; - this->rootDir = false; - vSubFiles = new std::vector; -} - -DirectoryEntry::DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags, DatEntry* hFileEntry ) { - this->name = name; - this->fFlags.raw = fFlags.raw; - vSubFiles = new std::vector; - AddEntry(hFileEntry); -} - -DirectoryEntry::~DirectoryEntry() { - for ( DatEntry* e : *vSubFiles ) - delete e; - delete vSubFiles; -} - -/*std::string DirectoryEntry::toString() { - -}*/ - -void DirectoryEntry::ClearLinkedFiles() { - vSubFiles->clear(); -} - -void DirectoryEntry::AddEntry( DatEntry* hFileEntry ) { - vSubFiles->push_back(hFileEntry); -} - -} diff --git a/src/RDat.cpp b/src/Erso.cpp similarity index 80% rename from src/RDat.cpp rename to src/Erso.cpp index 0ab3197..dd53823 100644 --- a/src/RDat.cpp +++ b/src/Erso.cpp @@ -1,9 +1,9 @@ /** - * @file RDat.cpp - * @date 20/09/2022 + * @file Erso.cpp + * @date 24/09/2022 * @author JackCarterSmith * @copyright GPL-v3.0 - * @brief Rogue Dat file class interface. + * @brief Rogue DATA/BUNDLE file parser and interface. * */ @@ -13,9 +13,9 @@ #include #include #include -#include "DatEntry.h" -#include "data_struct.h" -#include "RDat.h" +#include "files_mms/data_struct.h" +#include "Erso.hpp" +#include "ErsoEntry.hpp" using std::string; @@ -27,7 +27,7 @@ using boost::filesystem::file_size; namespace RDI { -RDat::RDat( string fPath ) { +Erso::Erso( string fPath ) { RDI_RESULT errCode = RDI_OK; this->workingDir = fPath; @@ -46,23 +46,23 @@ RDat::RDat( string fPath ) { ProcessFilesTree(); } -RDat::~RDat() { - for ( DirectoryEntry* de : *pFTRoot ) +Erso::~Erso() { + for ( ErsoEntryDir* de : *pFTRoot ) delete de; delete pFTRoot; free(rDatPtr); delete pDatSection; } -string RDat::getDataSectionName( unsigned char id ) { return pDatSection->at(id).name; } -unsigned int RDat::getDataSectionOffset( unsigned char id ) { return pDatSection->at(id).offset; } +string Erso::getDataSectionName( unsigned char id ) { return pDatSection->at(id).name; } +unsigned int Erso::getDataSectionOffset( unsigned char id ) { return pDatSection->at(id).offset; } /** * Helper function to search for legacy DATA.DAT/HDR and dump it in memory. * * @return Error status. */ -RDI_RESULT RDat::DumpLegacyFiles() { +RDI_RESULT Erso::DumpLegacyFiles() { unsigned int i; path fp(workingDir); MEMFILE pTmpFile; @@ -103,7 +103,7 @@ RDI_RESULT RDat::DumpLegacyFiles() { * * @return Start memory pointer of the file. */ -MEMFILE RDat::MallocFile( path filePath ) { +MEMFILE Erso::MallocFile( path filePath ) { const unsigned int size = file_size(filePath); std::fstream rdf; MEMFILE fPtr = NULL; @@ -123,16 +123,16 @@ MEMFILE RDat::MallocFile( path filePath ) { * * @return Error status. */ -RDI_RESULT RDat::ProcessFilesTree() { +RDI_RESULT Erso::ProcessFilesTree() { unsigned int curEntriesCount = 0, i; - DirectoryEntry* curDir = nullptr; + ErsoEntryDir* curDir = nullptr; MEMFILE pFileDescriptors = nullptr; // Create new root files tree. One per data section. - pFTRoot = new std::vector; + pFTRoot = new std::vector; pFTRoot->clear(); for ( i = 0; i < cDatSection; i++ ) { - curDir = new DirectoryEntry(pDatSection->at(i).name); + curDir = new ErsoEntryDir(pDatSection->at(i).name); pFTRoot->push_back(curDir); // Recalculate files descriptor offset for current section. @@ -147,12 +147,12 @@ RDI_RESULT RDat::ProcessFilesTree() { return RDI_OK; } -RDI_RESULT RDat::ProcessDirectoryContents( DirectoryEntry* pCurDir, MEMFILE pDesc, const unsigned int count, MEMFILE pSectionStart ) { +RDI_RESULT Erso::ProcessDirectoryContents( ErsoEntryDir* pCurDir, MEMFILE pDesc, const unsigned int count, MEMFILE pSectionStart ) { unsigned int i, newDRECnt; DAT_FILE_FLAGS curEntryFlags = {0}; - FileEntry* newFile = nullptr; - DirectoryEntry* newDir = nullptr; + ErsoEntryFile* newFile = nullptr; + ErsoEntryDir* newDir = nullptr; std::string tmpStr; if ( count == 0) return RDI_ERROR_PROCESS; @@ -165,12 +165,12 @@ RDI_RESULT RDat::ProcessDirectoryContents( DirectoryEntry* pCurDir, MEMFILE pDes // Test for file or directory if (!curEntryFlags.isDirectory) { - newFile = new FileEntry(tmpStr, curEntryFlags, + newFile = new ErsoEntryFile(tmpStr, curEntryFlags, ((T_FILE_HEADER*)(pDesc + i * sizeof(T_FILE_HEADER)))->datas_size, pSectionStart + ((T_FILE_HEADER*)(pDesc + i * sizeof(T_FILE_HEADER)))->datas_offset); pCurDir->AddEntry(newFile); } else { - newDir = new DirectoryEntry(tmpStr, curEntryFlags); + newDir = new ErsoEntryDir(tmpStr, curEntryFlags); pCurDir->AddEntry(newDir); // Keep entries count in new directory to jump over after processing it. @@ -183,11 +183,11 @@ RDI_RESULT RDat::ProcessDirectoryContents( DirectoryEntry* pCurDir, MEMFILE pDes return RDI_OK; } -DatEntry *RDat::getElement( boost::filesystem::path virtualDirPath ) { +ErsoEntry *Erso::getElement( boost::filesystem::path virtualDirPath ) { bool skip = false; boost::filesystem::path newPath; - for ( DatEntry* de : *pFTRoot ) { + for ( ErsoEntry* de : *pFTRoot ) { if (virtualDirPath.size() == 1 || virtualDirPath.begin() == --virtualDirPath.end()) { if (de->getName() == virtualDirPath.filename().string()) return de; @@ -198,7 +198,7 @@ DatEntry *RDat::getElement( boost::filesystem::path virtualDirPath ) { newPath.append(sp); skip = true; } - return SearchSectionForEntry(dynamic_cast(de), newPath); + return SearchSectionForEntry(dynamic_cast(de), newPath); } } } @@ -206,11 +206,11 @@ DatEntry *RDat::getElement( boost::filesystem::path virtualDirPath ) { return nullptr; } -DatEntry *RDat::SearchSectionForEntry( DirectoryEntry *curDir, boost::filesystem::path virtualDirPath ) { +ErsoEntry *Erso::SearchSectionForEntry( ErsoEntryDir *curDir, boost::filesystem::path virtualDirPath ) { bool skip = false; boost::filesystem::path newPath; - for ( DatEntry* e : curDir->getFiles() ) { + for ( ErsoEntry* e : curDir->getFiles() ) { if (virtualDirPath.size() == 1 || virtualDirPath.begin() == --virtualDirPath.end()) { if (e->getName() == virtualDirPath.filename().string()) return e; @@ -222,7 +222,7 @@ DatEntry *RDat::SearchSectionForEntry( DirectoryEntry *curDir, boost::filesystem skip = true; } //TODO: add safety when trying to access inside a file - return SearchSectionForEntry(dynamic_cast(e), newPath); + return SearchSectionForEntry(dynamic_cast(e), newPath); } } } diff --git a/src/RDat.h b/src/Erso.hpp similarity index 63% rename from src/RDat.h rename to src/Erso.hpp index 1c1d476..d39f7cc 100644 --- a/src/RDat.h +++ b/src/Erso.hpp @@ -1,20 +1,20 @@ /** - * @file RDat.h - * @date 15/09/2022 + * @file Erso.hpp + * @date 24/09/2022 * @author JackCarterSmith * @copyright GPL-v3.0 - * @brief Rogue Dat file class interface. + * @brief Rogue DATA/BUNDLE file parser and interface. * */ #include #include -#include "DatEntry.h" #include "RDI_Datatypes.h" +#include "ErsoEntry.hpp" -#ifndef RDAT_H_ -#define RDAT_H_ +#ifndef ERSO_HPP_ +#define ERSO_HPP_ namespace RDI { @@ -23,10 +23,15 @@ struct dataSection { unsigned int offset = 0; }; -class RDat final { +/** + * Erso is class codename of the DATA/BUNDLE file parser of RDI library. + * + * @pre RDI should construct Erso class before doing anything on datas. + */ +class Erso final { public: - RDat( std::string fPath ); - ~RDat(); + Erso( std::string fPath ); + ~Erso(); MEMFILE getRDat() { return rDatPtr; @@ -39,7 +44,7 @@ public: std::string getDataSectionName( unsigned char id ); unsigned int getDataSectionOffset( unsigned char id ); - DatEntry *getElement( boost::filesystem::path virtualDirPath ); + ErsoEntry *getElement( boost::filesystem::path virtualDirPath ); private: std::string workingDir = "."; @@ -48,24 +53,24 @@ private: std::vector *pDatSection = nullptr; MEMFILE rDatPtr = nullptr; - std::vector *pFTRoot = nullptr; + std::vector *pFTRoot = nullptr; /* File processing methods */ RDI_RESULT DumpLegacyFiles(); MEMFILE MallocFile( boost::filesystem::path filePath ); RDI_RESULT ProcessFilesTree(); RDI_RESULT ProcessDirectoryContents( - DirectoryEntry* pCurDir, + ErsoEntryDir* pCurDir, MEMFILE pDesc, const unsigned int count, MEMFILE pSectionStart ); /* Tree manipulation/parse methods */ - DatEntry *SearchSectionForEntry( DirectoryEntry *curDir, boost::filesystem::path virtualDirPath); + ErsoEntry *SearchSectionForEntry( ErsoEntryDir *curDir, boost::filesystem::path virtualDirPath); }; } /* namespace RDI */ -#endif /* RDAT_H_ */ +#endif /* ERSO_HPP_ */ diff --git a/src/ErsoEntry.cpp b/src/ErsoEntry.cpp new file mode 100644 index 0000000..52ff513 --- /dev/null +++ b/src/ErsoEntry.cpp @@ -0,0 +1,68 @@ +/** + * @file ErsoDatEntry.cpp + * @date 24/09/2022 + * @author JackCarterSmith + * @copyright GPL-v3.0 + * @brief Data file entry descriptor class. + * + */ + +#include "ErsoEntry.hpp" + + +namespace RDI { + +ErsoEntryFile::ErsoEntryFile( std::string name, DAT_FILE_FLAGS fFlags, unsigned int size, MEMFILE fPtr ) { + this->name = name; + this->size = size; + this->fFlags.raw = fFlags.raw; + this->fileMemPtr = fPtr; +} + +ErsoEntryFile::~ErsoEntryFile() {} + +/*std::string FileEntry::toString() { + +}*/ + + +ErsoEntryDir::ErsoEntryDir( std::string name ) { + this->name = name; + this->fFlags.raw = 0; + this->rootDir = true; + vSubFiles = new std::vector; +} + +ErsoEntryDir::ErsoEntryDir( std::string name, DAT_FILE_FLAGS fFlags ) { + this->name = name; + this->fFlags.raw = fFlags.raw; + this->rootDir = false; + vSubFiles = new std::vector; +} + +ErsoEntryDir::ErsoEntryDir( std::string name, DAT_FILE_FLAGS fFlags, ErsoEntry* hFileEntry ) { + this->name = name; + this->fFlags.raw = fFlags.raw; + vSubFiles = new std::vector; + AddEntry(hFileEntry); +} + +ErsoEntryDir::~ErsoEntryDir() { + for ( ErsoEntry* e : *vSubFiles ) + delete e; + delete vSubFiles; +} + +/*std::string DirectoryEntry::toString() { + +}*/ + +void ErsoEntryDir::ClearLinkedFiles() { + vSubFiles->clear(); +} + +void ErsoEntryDir::AddEntry( ErsoEntry* hFileEntry ) { + vSubFiles->push_back(hFileEntry); +} + +} diff --git a/src/DatEntry.h b/src/ErsoEntry.hpp similarity index 60% rename from src/DatEntry.h rename to src/ErsoEntry.hpp index 119ed75..5c6ac88 100644 --- a/src/DatEntry.h +++ b/src/ErsoEntry.hpp @@ -1,19 +1,19 @@ /** - * @file DatEntry.h - * @date 20/09/2022 + * @file ErsoEntry.hpp + * @date 24/09/2022 * @author JackCarterSmith * @copyright GPL-v3.0 * @brief Data file entry descriptor class. * */ -#include "RDI_Datatypes.h" +#include #include #include -#ifndef DATENTRY_H_ -#define DATENTRY_H_ +#ifndef ERSOENTRY_HPP_ +#define ERSOENTRY_HPP_ namespace RDI { @@ -33,9 +33,9 @@ typedef union u_file_flags { -class DatEntry { +class ErsoEntry { public: - virtual ~DatEntry() = 0; + virtual ~ErsoEntry() = 0; virtual bool isDirectory() = 0; virtual bool isRootDirectory() = 0; //virtual std::string toString() = 0; @@ -48,12 +48,12 @@ protected: DAT_FILE_FLAGS fFlags; }; -inline DatEntry::~DatEntry() {} +inline ErsoEntry::~ErsoEntry() {} -class FileEntry : public DatEntry { +class ErsoEntryFile : public ErsoEntry { public: - FileEntry( std::string name, DAT_FILE_FLAGS fFlags, unsigned int size, MEMFILE fPtr ); - ~FileEntry(); + ErsoEntryFile( std::string name, DAT_FILE_FLAGS fFlags, unsigned int size, MEMFILE fPtr ); + ~ErsoEntryFile(); MEMFILE getDatas() { return fileMemPtr; } @@ -68,16 +68,16 @@ private: }; -class DirectoryEntry : public DatEntry { +class ErsoEntryDir : public ErsoEntry { public: - DirectoryEntry( std::string name ); - DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags ); - DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags, DatEntry* hFileEntry ); - ~DirectoryEntry(); + ErsoEntryDir( std::string name ); + ErsoEntryDir( std::string name, DAT_FILE_FLAGS fFlags ); + ErsoEntryDir( std::string name, DAT_FILE_FLAGS fFlags, ErsoEntry* hFileEntry ); + ~ErsoEntryDir(); void ClearLinkedFiles(); - void AddEntry( DatEntry* hFileEntry ); - std::vector getFiles() { return *vSubFiles; } + void AddEntry( ErsoEntry* hFileEntry ); + std::vector getFiles() { return *vSubFiles; } //std::string toString(); bool isDirectory() { return true; } @@ -86,9 +86,9 @@ public: private: bool rootDir; - std::vector *vSubFiles; + std::vector *vSubFiles; }; } -#endif /* DATENTRY_H_ */ +#endif /* ERSODATENTRY_HPP_ */ diff --git a/src/Krennic.cpp b/src/Krennic.cpp new file mode 100644 index 0000000..5a447e2 --- /dev/null +++ b/src/Krennic.cpp @@ -0,0 +1,98 @@ +/** + * @file Krennic.cpp + * @date 24/09/2022 + * @author JackCarterSmith + * @copyright GPL-v3.0 + * @brief Main game assets parser and interface. + * + * Complete class would take Erso legacy files tree and extract levels, objects, + * textures, animations, etc. adapted datas for OpenGL/Direct3D application. + * + */ + +#include +#include +#include +#include +#include "Erso.hpp" +#include "Krennic.hpp" + + +namespace RDI { + +Krennic::Krennic( Erso* pErso ) { + BuildLevelList(pErso); + BuildModelList(pErso); + BuildTextureList(pErso); + BuildMusicList(pErso); + BuildSampleList(pErso); +} + +Krennic::~Krennic() {} + + +void Krennic::BuildLevelList( Erso* pErso ) { + const static std::string legacyLvlPath = "data/level"; + ErsoEntryDir* levelDir = nullptr; + + listLevel.clear(); + levelDir = dynamic_cast(pErso->getElement(boost::filesystem::path(legacyLvlPath))); + if (levelDir != nullptr) { + for ( ErsoEntry* fl : levelDir->getFiles() ) { + if (fl->isDirectory()) { + if (pErso->getElement(boost::filesystem::path(legacyLvlPath).append(fl->getName()).append("dat")) != nullptr) { + listLevel.push_back(legacyLvlPath + "/" + fl->getName()); + } + } + } + } + + //TODO: LvlClass builder +} + +void Krennic::BuildModelList( Erso* pErso ) { + const static std::vector legacyModelPath = { + "data/pl_crafts", "data/reb_stuff", "data/imp_stuff", + "data/gnrc_stuff", "data2" + }; + ErsoEntryDir* curModelDir = nullptr; + + listModel.clear(); + for ( std::string path_it : legacyModelPath ) { + curModelDir = dynamic_cast(pErso->getElement(boost::filesystem::path(path_it))); + if (curModelDir != nullptr) { + for ( ErsoEntry* fl : curModelDir->getFiles() ) { + if (fl->getName().find("_HOB") != std::string::npos) { + listModel.push_back(path_it + "/" + fl->getName()); + } + } + } + } +} + +void Krennic::BuildTextureList( Erso* pErso ) { + +} + +void Krennic::BuildMusicList( Erso* pErso ) { + const static std::string legacyMusicPath = "data/sound"; + ErsoEntryDir* musicDir = nullptr; + + listMusic.clear(); + musicDir = dynamic_cast(pErso->getElement(boost::filesystem::path(legacyMusicPath))); + if (musicDir != nullptr) { + for ( ErsoEntry* fl : musicDir->getFiles() ) { + //TODO: MusyX-Class builder + + if (fl->getName().find("_SNG") != std::string::npos) { + listMusic.push_back(legacyMusicPath + "/" + fl->getName()); + } + } + } +} + +void Krennic::BuildSampleList( Erso* pErso ) { + +} + +} diff --git a/src/LegacyExplorer.h b/src/Krennic.hpp similarity index 73% rename from src/LegacyExplorer.h rename to src/Krennic.hpp index 0dde00d..ee74fb8 100644 --- a/src/LegacyExplorer.h +++ b/src/Krennic.hpp @@ -1,11 +1,11 @@ /** - * @file LegacyExplorer.h - * @date 22/09/2022 + * @file Krennic.hpp + * @date 24/09/2022 * @author JackCarterSmith * @copyright GPL-v3.0 - * @brief Main game resources interface. + * @brief Main game assets parser and interface. * - * Complete class would take legacy RDat files tree and extract levels, objects, + * Complete class would take Erso legacy files tree and extract levels, objects, * textures, animations, etc. adapted datas for OpenGL/Direct3D application. * */ @@ -13,20 +13,20 @@ #include #include #include -#include "RDat.h" -#include "datfiles/GenericFile.h" -#include "datfiles/HMT.h" +#include +#include +#include "Erso.hpp" -#ifndef LEGACYEXPLORER_H_ -#define LEGACYEXPLORER_H_ +#ifndef KRENNIC_HPP_ +#define KRENNIC_HPP_ namespace RDI { -class LegacyExplorer final { +class Krennic final { public: - LegacyExplorer( RDat* pRDat ); - ~LegacyExplorer(); + Krennic( Erso* pErso ); + ~Krennic(); /** * Retrieve know list of legacy game files type. @@ -70,13 +70,13 @@ private: std::vector listMusic; std::vector listSample; - void BuildLevelList( RDat* pRDat ); - void BuildModelList( RDat* pRDat ); - void BuildTextureList( RDat* pRDat ); - void BuildMusicList( RDat* pRDat ); - void BuildSampleList( RDat* pRDat ); + void BuildLevelList( Erso* pErso ); + void BuildModelList( Erso* pErso ); + void BuildTextureList( Erso* pErso ); + void BuildMusicList( Erso* pErso ); + void BuildSampleList( Erso* pErso ); }; } -#endif /* LEGACYEXPLORER_H_ */ +#endif /* KRENNIC_HPP_ */ diff --git a/src/datfiles/GenericFile.cpp b/src/KrennicHandlerGeneric.cpp similarity index 76% rename from src/datfiles/GenericFile.cpp rename to src/KrennicHandlerGeneric.cpp index 5cbf8bd..54bf350 100644 --- a/src/datfiles/GenericFile.cpp +++ b/src/KrennicHandlerGeneric.cpp @@ -8,12 +8,12 @@ */ #include -#include "../DatEntry.h" -#include "GenericFile.h" +#include +#include "ErsoEntry.hpp" namespace RDI { -GenericFile::GenericFile( FileEntry& hDat ) { +GenericFile::GenericFile( ErsoEntryFile& hDat ) { this->size = hDat.getSize(); this->fileName = hDat.getName(); this->fileExtension = ""; diff --git a/src/datfiles/HMT.cpp b/src/KrennicHandlerHMT.cpp similarity index 63% rename from src/datfiles/HMT.cpp rename to src/KrennicHandlerHMT.cpp index 5bc0586..66baf43 100644 --- a/src/datfiles/HMT.cpp +++ b/src/KrennicHandlerHMT.cpp @@ -7,13 +7,13 @@ * */ -#include "GenericFile.h" -#include "HMT.h" +#include +#include namespace RDI { -HMT::HMT( FileEntry& hDat ): GenericFile( hDat ) { +HMT::HMT( ErsoEntryFile& hDat ): GenericFile( hDat ) { this->fileExtension = "hmt"; } diff --git a/src/LegacyExplorer.cpp b/src/LegacyExplorer.cpp deleted file mode 100644 index 7fb56bc..0000000 --- a/src/LegacyExplorer.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/** - * @file LegacyExplorer.cpp - * @date 22/09/2022 - * @author JackCarterSmith - * @copyright GPL-v3.0 - * @brief Main game resources interface. - * - * Complete class would take legacy RDat files tree and extract levels, objects, - * textures, animations, etc. adapted datas for OpenGL/Direct3D application. - * - */ - -#include -#include -#include -#include -#include "RDat.h" -#include "LegacyExplorer.h" - - -namespace RDI { - -LegacyExplorer::LegacyExplorer( RDat* pRDat ) { - BuildLevelList(pRDat); - BuildModelList(pRDat); - BuildTextureList(pRDat); - BuildMusicList(pRDat); - BuildSampleList(pRDat); -} - -LegacyExplorer::~LegacyExplorer() {} - - -void LegacyExplorer::BuildLevelList( RDat* pRDat ) { - const static std::string legacyLvlPath = "data/level"; - DirectoryEntry* levelDir = nullptr; - - listLevel.clear(); - levelDir = dynamic_cast(pRDat->getElement(boost::filesystem::path(legacyLvlPath))); - if (levelDir != nullptr) { - for ( DatEntry* fl : levelDir->getFiles() ) { - if (fl->isDirectory()) { - if (pRDat->getElement(boost::filesystem::path(legacyLvlPath).append(fl->getName()).append("dat")) != nullptr) { - listLevel.push_back(legacyLvlPath + "/" + fl->getName()); - } - } - } - } - - //TODO: LvlClass builder -} - -void LegacyExplorer::BuildModelList( RDat* pRDat ) { - const static std::vector legacyModelPath = { - "data/pl_crafts", "data/reb_stuff", "data/imp_stuff", - "data/gnrc_stuff", "data2" - }; - DirectoryEntry* curModelDir = nullptr; - - listModel.clear(); - for ( std::string path_it : legacyModelPath ) { - curModelDir = dynamic_cast(pRDat->getElement(boost::filesystem::path(path_it))); - if (curModelDir != nullptr) { - for ( DatEntry* fl : curModelDir->getFiles() ) { - if (fl->getName().find("_HOB") != std::string::npos) { - listModel.push_back(path_it + "/" + fl->getName()); - } - } - } - } -} - -void LegacyExplorer::BuildTextureList( RDat* pRDat ) { - -} - -void LegacyExplorer::BuildMusicList( RDat* pRDat ) { - const static std::string legacyMusicPath = "data/sound"; - DirectoryEntry* musicDir = nullptr; - - listMusic.clear(); - musicDir = dynamic_cast(pRDat->getElement(boost::filesystem::path(legacyMusicPath))); - if (musicDir != nullptr) { - for ( DatEntry* fl : musicDir->getFiles() ) { - //TODO: MusyX-Class builder - - if (fl->getName().find("_SNG") != std::string::npos) { - listMusic.push_back(legacyMusicPath + "/" + fl->getName()); - } - } - } -} - -void LegacyExplorer::BuildSampleList( RDat* pRDat ) { - -} - -} diff --git a/src/RDI.cpp b/src/RDI.cpp index 1e62b1d..caa4b26 100644 --- a/src/RDI.cpp +++ b/src/RDI.cpp @@ -1,9 +1,9 @@ /** * @file RDI.cpp - * @date 15/09/2022 + * @date 24/09/2022 * @author JackCarterSmith * @copyright GPL-v3.0 - * @brief Rogue Data Interface library main entry file. + * @brief Rogue Data Interface library main entry abstraction file. * */ @@ -16,17 +16,17 @@ #include #include #include "config.h" -#include "RDat.h" -#include "DatEntry.h" -#include "LegacyExplorer.h" -#include "RDI.h" +#include "Erso.hpp" +#include "ErsoEntry.hpp" +#include "Krennic.hpp" +#include "RDI.hpp" /* * Internal variable */ -static RDI::RDat *hRDat = nullptr; -static RDI::LegacyExplorer *hLegacyExp = nullptr; +static RDI::Erso *hErsoModule = nullptr; +static RDI::Krennic *hKrennicModule = nullptr; /* * Libs interface @@ -35,55 +35,55 @@ static RDI::LegacyExplorer *hLegacyExp = nullptr; std::string RDI::getLibVersion() { return PRG_VERSION; } void RDI::CreateRDatHandler( std::string roguePath ){ - if (hRDat == nullptr) hRDat = new RDI::RDat(roguePath); + if (hErsoModule == nullptr) hErsoModule = new RDI::Erso(roguePath); - //return hRDat; + //return hErsoModule; } void RDI::CreateLegacyHandler( void ){ - if (hRDat != nullptr) hLegacyExp = new RDI::LegacyExplorer(hRDat); + if (hErsoModule != nullptr) hKrennicModule = new RDI::Krennic(hErsoModule); - //return hLegacyExp; + //return hKrennicModule; } unsigned char RDI::getSectionCount() { - if (hRDat == nullptr) return 0; - else return hRDat->getDataSectionCount(); + if (hErsoModule == nullptr) return 0; + else return hErsoModule->getDataSectionCount(); } std::string RDI::getSectionName( unsigned char id ) { - if (hRDat == nullptr) return ""; - else return hRDat->getDataSectionName(id); + if (hErsoModule == nullptr) return ""; + else return hErsoModule->getDataSectionName(id); } unsigned int RDI::getSectionOffset( unsigned char id ) { - if (hRDat == nullptr) return 0; - else return hRDat->getDataSectionOffset(id); + if (hErsoModule == nullptr) return 0; + else return hErsoModule->getDataSectionOffset(id); } unsigned int RDI::getDirectoryElementCount( std::string path ) { - DirectoryEntry* result = nullptr; + ErsoEntryDir* result = nullptr; if (path.empty()) return 0; - result = dynamic_cast(hRDat->getElement(boost::filesystem::path(path))); + result = dynamic_cast(hErsoModule->getElement(boost::filesystem::path(path))); if (result == nullptr) return 0; else return result->getSize(); } std::vector RDI::getDirectoryElements( std::string path ) { - DirectoryEntry* de = nullptr; + ErsoEntryDir* de = nullptr; std::vector elementsNameArray; elementsNameArray.clear(); if (!path.empty()) { - de = dynamic_cast(hRDat->getElement(boost::filesystem::path(path))); + de = dynamic_cast(hErsoModule->getElement(boost::filesystem::path(path))); if (de != nullptr && de->isDirectory()) { - for (DatEntry* de2 : de->getFiles()) + for (ErsoEntry* de2 : de->getFiles()) elementsNameArray.push_back(de2->getName()); } } @@ -92,11 +92,11 @@ std::vector RDI::getDirectoryElements( std::string path ) { } bool RDI::isElementDirectory( std::string path ) { - DatEntry* result = nullptr; + ErsoEntry* result = nullptr; if (path.empty()) return false; - result = hRDat->getElement(boost::filesystem::path(path)); + result = hErsoModule->getElement(boost::filesystem::path(path)); if (result == nullptr) return false; else return (result->isDirectory() || result->isRootDirectory()); @@ -104,21 +104,21 @@ bool RDI::isElementDirectory( std::string path ) { std::vector RDI::getLevelsName( void ) { - return hLegacyExp->getLevelsList(); + return hKrennicModule->getLevelsList(); } std::vector RDI::getModelsName( void ) { - return hLegacyExp->getModelsList(); + return hKrennicModule->getModelsList(); } std::vector RDI::getMusicsName( void ) { - return hLegacyExp->getMusicsList(); + return hKrennicModule->getMusicsList(); } void RDI::DestroyRDatHandler(){ - if (hRDat) delete hRDat; + if (hErsoModule) delete hErsoModule; } void RDI::DestroyLegacyHandler(){ - if (hLegacyExp) delete hLegacyExp; + if (hKrennicModule) delete hKrennicModule; } diff --git a/src/bundle_struct.h b/src/files_mms/bundle_struct.h similarity index 100% rename from src/bundle_struct.h rename to src/files_mms/bundle_struct.h diff --git a/src/data_struct.h b/src/files_mms/data_struct.h similarity index 100% rename from src/data_struct.h rename to src/files_mms/data_struct.h diff --git a/tools/ErsoDebug.cpp b/tools/ErsoDebug.cpp new file mode 100644 index 0000000..4cb30bd --- /dev/null +++ b/tools/ErsoDebug.cpp @@ -0,0 +1,16 @@ +/** + * @file ErsoDebug.cpp + * @date 24/09/2022 + * @author JackCarterSmith + * @copyright GPL-v3.0 + * @brief Debug app to test Erso module of RDI library. + * + */ + +#include + + +int main( int argc, char *argv[] ) { + + return 0; +} diff --git a/tools/KrennicDebug.cpp b/tools/KrennicDebug.cpp new file mode 100644 index 0000000..1e2812f --- /dev/null +++ b/tools/KrennicDebug.cpp @@ -0,0 +1,16 @@ +/** + * @file KrennicDebug.cpp + * @date 24/09/2022 + * @author JackCarterSmith + * @copyright GPL-v3.0 + * @brief Debug app to test Krennic module of RDI library. + * + */ + +#include + + +int main( int argc, char *argv[] ) { + + return 0; +} diff --git a/tools/RDIdebug.cpp b/tools/RDIdebug.cpp index 6887aca..dd0100e 100644 --- a/tools/RDIdebug.cpp +++ b/tools/RDIdebug.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include void PrintVirtualDirectoryContents( boost::filesystem::path, std::string );