diff --git a/include/RDI.h b/include/RDI.h index 4746737..cdb1d81 100644 --- a/include/RDI.h +++ b/include/RDI.h @@ -58,6 +58,7 @@ namespace RDI { * @return Handler of RogueData file, should be used with other function of this lib. */ RDI_EXTERN void CreateRDatHandler( std::string roguePath ); + RDI_EXTERN void CreateLegacyHandler( void ); RDI_EXTERN unsigned char getSectionCount( void ); RDI_EXTERN std::string getSectionName( unsigned char id ); @@ -67,10 +68,16 @@ namespace RDI { RDI_EXTERN std::vector getDirectoryElements( std::string path ); RDI_EXTERN bool isElementDirectory( std::string path ); + + RDI_EXTERN std::vector getLevelsName( void ); + RDI_EXTERN std::vector getModelsName( void ); + RDI_EXTERN std::vector getMusicsName( void ); + /** * @brief Clean up global resources. */ RDI_EXTERN void DestroyRDatHandler( void ); + RDI_EXTERN void DestroyLegacyHandler( void ); } diff --git a/src/LegacyExplorer.cpp b/src/LegacyExplorer.cpp index ed37682..7fb56bc 100644 --- a/src/LegacyExplorer.cpp +++ b/src/LegacyExplorer.cpp @@ -13,19 +13,86 @@ #include #include #include +#include #include "RDat.h" #include "LegacyExplorer.h" namespace RDI { -LegacyExplorer::LegacyExplorer( RDat& pRDat ) { - // TODO Auto-generated constructor stub +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 ) { } -LegacyExplorer::~LegacyExplorer() { - // TODO Auto-generated destructor stub +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/LegacyExplorer.h b/src/LegacyExplorer.h index 553cfb6..0dde00d 100644 --- a/src/LegacyExplorer.h +++ b/src/LegacyExplorer.h @@ -10,6 +10,14 @@ * */ +#include +#include +#include +#include "RDat.h" +#include "datfiles/GenericFile.h" +#include "datfiles/HMT.h" + + #ifndef LEGACYEXPLORER_H_ #define LEGACYEXPLORER_H_ @@ -17,8 +25,56 @@ namespace RDI { class LegacyExplorer final { public: - LegacyExplorer( RDat& pRDat ); + LegacyExplorer( RDat* pRDat ); ~LegacyExplorer(); + + /** + * Retrieve know list of legacy game files type. + * @return Array of filtered elements. + */ + ///@{ + std::vector getLevelsList() { return listLevel; } + std::vector getModelsList() { return listModel; } + std::vector getTexturesList() { return listTexture; } + std::vector getMusicsList() { return listMusic; } + std::vector getSamplesList() { return listSample; } + ///@} + + /** + * Obtain the class interface for datas in specified file type. + * @param name Name of the file, should be in list. + * @return File type class handler. + */ + ///@{ + void* getLevel( std::string name ); + void* getModel( std::string name ); + HMT *getTexture( std::string name ); + void* getMusic( std::string name ); + void* getSample( std::string name ); + ///@} + + /** + * @brief Retrieve default file instance. + * @details Unknown file type can be wrapped in dummy class to access raw + * content without parsing or other type of processing. + * + * @param[in] vPath Virtual path to the file. + * @return Generic file type class handler. + */ + GenericFile *getFile( boost::filesystem::path vPath ); + +private: + std::vector listLevel; + std::vector listModel; + std::vector listTexture; + 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 ); }; } diff --git a/src/RDI.cpp b/src/RDI.cpp index 93fe10a..1e62b1d 100644 --- a/src/RDI.cpp +++ b/src/RDI.cpp @@ -18,6 +18,7 @@ #include "config.h" #include "RDat.h" #include "DatEntry.h" +#include "LegacyExplorer.h" #include "RDI.h" @@ -25,6 +26,7 @@ * Internal variable */ static RDI::RDat *hRDat = nullptr; +static RDI::LegacyExplorer *hLegacyExp = nullptr; /* * Libs interface @@ -38,6 +40,12 @@ void RDI::CreateRDatHandler( std::string roguePath ){ //return hRDat; } +void RDI::CreateLegacyHandler( void ){ + if (hRDat != nullptr) hLegacyExp = new RDI::LegacyExplorer(hRDat); + + //return hLegacyExp; +} + unsigned char RDI::getSectionCount() { if (hRDat == nullptr) return 0; @@ -95,6 +103,22 @@ bool RDI::isElementDirectory( std::string path ) { } +std::vector RDI::getLevelsName( void ) { + return hLegacyExp->getLevelsList(); +} + +std::vector RDI::getModelsName( void ) { + return hLegacyExp->getModelsList(); +} + +std::vector RDI::getMusicsName( void ) { + return hLegacyExp->getMusicsList(); +} + void RDI::DestroyRDatHandler(){ if (hRDat) delete hRDat; } + +void RDI::DestroyLegacyHandler(){ + if (hLegacyExp) delete hLegacyExp; +} diff --git a/src/datfiles/GenericFile.cpp b/src/datfiles/GenericFile.cpp new file mode 100644 index 0000000..5cbf8bd --- /dev/null +++ b/src/datfiles/GenericFile.cpp @@ -0,0 +1,25 @@ +/** + * @file GenericFile.cpp + * @date 23/09/2022 + * @author JackCarterSmith + * @copyright GPL-v3.0 + * @brief Generic file object class. + * + */ + +#include +#include "../DatEntry.h" +#include "GenericFile.h" + +namespace RDI { + +GenericFile::GenericFile( FileEntry& hDat ) { + this->size = hDat.getSize(); + this->fileName = hDat.getName(); + this->fileExtension = ""; + this->pMemLoc = hDat.getDatas(); +} + +GenericFile::~GenericFile() {} + +} diff --git a/src/datfiles/GenericFile.h b/src/datfiles/GenericFile.h new file mode 100644 index 0000000..1475e6d --- /dev/null +++ b/src/datfiles/GenericFile.h @@ -0,0 +1,34 @@ +/** + * @file GenericFile.h + * @date 23/09/2022 + * @author JackCarterSmith + * @copyright GPL-v3.0 + * @brief Generic file object class. + * + */ + +#include +#include "../DatEntry.h" + + +#ifndef GENERICFILE_H_ +#define GENERICFILE_H_ + +namespace RDI { + +class GenericFile { +public: + GenericFile( FileEntry& hDat ); + virtual ~GenericFile(); + + MEMFILE get() { return pMemLoc; } + +protected: + unsigned long size; + std::string fileName, fileExtension; + MEMFILE pMemLoc = nullptr; +}; + +} + +#endif /* GENERICFILE_H_ */ diff --git a/src/datfiles/HMT.cpp b/src/datfiles/HMT.cpp index 77ed7eb..5bc0586 100644 --- a/src/datfiles/HMT.cpp +++ b/src/datfiles/HMT.cpp @@ -7,17 +7,16 @@ * */ +#include "GenericFile.h" #include "HMT.h" + namespace RDI { -HMT::HMT() { - // TODO Auto-generated constructor stub - +HMT::HMT( FileEntry& hDat ): GenericFile( hDat ) { + this->fileExtension = "hmt"; } -HMT::~HMT() { - // TODO Auto-generated destructor stub -} +HMT::~HMT() {} -} /* namespace RDI */ +} diff --git a/src/datfiles/HMT.h b/src/datfiles/HMT.h index c6c8cb7..e4d108e 100644 --- a/src/datfiles/HMT.h +++ b/src/datfiles/HMT.h @@ -7,17 +7,20 @@ * */ -#ifndef SRC_DATFILES_HMT_H_ -#define SRC_DATFILES_HMT_H_ +#include "GenericFile.h" + + +#ifndef HMT_H_ +#define HMT_H_ namespace RDI { -class HMT { +class HMT : public GenericFile { public: - HMT(); + HMT( FileEntry& hDat ); virtual ~HMT(); }; -} /* namespace RDI */ +} -#endif /* SRC_DATFILES_HMT_H_ */ +#endif /* HMT_H_ */ diff --git a/tools/RDIdebug.cpp b/tools/RDIdebug.cpp index 61a7e30..6887aca 100644 --- a/tools/RDIdebug.cpp +++ b/tools/RDIdebug.cpp @@ -46,6 +46,17 @@ int main( int argc, char *argv[] ) { PrintVirtualDirectoryContents(pathBuilder, prefix); } + RDI::CreateLegacyHandler(); + for ( std::string lname : RDI::getLevelsName() ) { + printf("Level found: %s\n", lname.c_str()); + } + for ( std::string mdname : RDI::getModelsName() ) { + printf("Model found: %s\n", mdname.c_str()); + } + for ( std::string mname : RDI::getMusicsName() ) { + printf("Music found: %s\n", mname.c_str()); + } + RDI::DestroyRDatHandler(); return 0;