/** * @file RDI.cpp * @date 04/02/2023 * @author JackCarterSmith * @copyright GPL-v3.0 * @brief Rogue Data Interface library main entry abstraction file. * */ #if !(__cplusplus < 201703L) && !(_MSVC_LANG < 201703L) #error "This code run on C++17 or upper." #endif #if defined(RDI_DLL) # define RDI_DLLBUILD #endif #include #include #include #include #include #include // Only for version getting, no processing. #include // Only for version getting, no processing. #include "config.h" #include "Erso.hpp" #include "DatFileEntry.hpp" #include "Krennic.hpp" #include #include "RDI.hpp" using namespace RDI::DatFile; /* * Internal modules instance */ static RDI::Erso *ErsoModule = nullptr; static RDI::Krennic *KrennicModule = nullptr; /* * Libs interface */ const std::string RDI::RDI_getLibVersion() noexcept { return PRG_VERSION; } void RDI::RDI_Init( std::string roguePath ) { #ifndef NDEBUG std::cout << std::endl << "[RDI][DBG] Running RDI v" << std::string(RDI::RDI_getLibVersion()) << std::endl; std::cout << "[RDI][DBG] - RSPModelLib v" << std::string(RSPModel_getVersion()) << std::endl; std::cout << "[RDI][DBG] - RSPTerrainLib v" << std::string(RSPTerrain_getVersion()) << std::endl; std::cout << "[RDI][DBG] - RSPTextureLib v" << "N/A" << std::endl; #endif // Create new instance of Erso module // Load and extract datas files from DATA.DAT if (ErsoModule == nullptr) { #ifndef NDEBUG std::cout << "[RDI][DBG] Loading Erso module..." << std::endl; #endif ErsoModule = new RDI::Erso(roguePath); } // Create new instance of Krennic module // Process datas from Erso and build new dataset to be used outside this library if (ErsoModule != nullptr && KrennicModule == nullptr) { #ifndef NDEBUG std::cout << "[RDI][DBG] Loading Krennic module..." << std::endl; #endif KrennicModule = new RDI::Krennic(ErsoModule); } } const unsigned char RDI::RDI_getSectionCount() { if (ErsoModule == nullptr) return 0; else return ErsoModule->getDataSectionCount(); } const std::string RDI::RDI_getSectionName( unsigned char id ) { if (ErsoModule == nullptr) return ""; else return ErsoModule->getDataSectionName(id); } const unsigned int RDI::RDI_getSectionOffset( unsigned char id ) { if (ErsoModule == nullptr) return 0; else return ErsoModule->getDataSectionOffset(id); } const unsigned int RDI::RDI_getDirectoryElementCount( std::string path ) { DatFileEntryDirectory* result = nullptr; if (path.empty()) return 0; result = dynamic_cast(ErsoModule->getElement(boost::filesystem::path(path))); if (result == nullptr) return 0; else return result->getSize(); } const std::vector RDI::RDI_getDirectoryElements( std::string path ) { DatFileEntryDirectory* de = nullptr; std::vector elementsNameArray; elementsNameArray.clear(); if (!path.empty()) { de = dynamic_cast(ErsoModule->getElement(boost::filesystem::path(path))); if (de != nullptr && de->isDirectory()) { for (DatFileEntry* de2 : de->getFiles()) elementsNameArray.push_back(de2->getName()); } } return elementsNameArray; } const bool RDI::RDI_isElementDirectory( std::string path ) { DatFileEntry* result = nullptr; if (path.empty()) return false; result = ErsoModule->getElement(boost::filesystem::path(path)); if (result == nullptr) return false; else return (result->isDirectory() || result->isRootDirectory()); } /* -------------------------------------------------------------------------- */ const std::vector RDI::RDI_getLevelsName( void ) noexcept { return KrennicModule->getLevelsList(); } const std::vector RDI::RDI_getModelsName( void ) noexcept { return KrennicModule->getModelsList(); } const std::vector RDI::RDI_getTexturesName( void ) noexcept { return KrennicModule->getTexturesList(); } const std::vector RDI::RDI_getMusicsName( void ) noexcept { return KrennicModule->getMusicsList(); } RDI::LVL* RDI::RDI_getLevel( std::string levelName ) { try { return KrennicModule->getLevel(levelName); } catch (std::invalid_argument const &ex) { // Can't find level, incorrect name? throw std::invalid_argument(ex); } } RDI::HOB* RDI::RDI_getModel( std::string modelName ) { try { return KrennicModule->getModel(modelName); } catch (std::invalid_argument const &ex) { // Can't find model, incorrect name? throw std::invalid_argument(ex); } } /* -------------------------------------------------------------------------- */ void RDI::RDI_CleanUp(){ if (KrennicModule) delete KrennicModule; if (ErsoModule) delete ErsoModule; }