Reforge library structure - 1st pass
This commit is contained in:
parent
c33ee14f36
commit
b21372d1b9
@ -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()
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../RDI_Datatypes.h"
|
||||
#include <string>
|
||||
#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; }
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "GenericFile.h"
|
||||
#include <FileHandler/Generic.h>
|
||||
|
||||
|
||||
#ifndef HMT_H_
|
||||
@ -17,7 +17,7 @@ namespace RDI {
|
||||
|
||||
class HMT : public GenericFile {
|
||||
public:
|
||||
HMT( FileEntry& hDat );
|
||||
HMT( ErsoEntryFile& hDat );
|
||||
virtual ~HMT();
|
||||
};
|
||||
|
@ -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 <string>
|
||||
#include <vector>
|
||||
#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_ */
|
@ -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<DatEntry*>;
|
||||
}
|
||||
|
||||
DirectoryEntry::DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags ) {
|
||||
this->name = name;
|
||||
this->fFlags.raw = fFlags.raw;
|
||||
this->rootDir = false;
|
||||
vSubFiles = new std::vector<DatEntry*>;
|
||||
}
|
||||
|
||||
DirectoryEntry::DirectoryEntry( std::string name, DAT_FILE_FLAGS fFlags, DatEntry* hFileEntry ) {
|
||||
this->name = name;
|
||||
this->fFlags.raw = fFlags.raw;
|
||||
vSubFiles = new std::vector<DatEntry*>;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -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 <vector>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <RDI_Datatypes.h>
|
||||
#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<DirectoryEntry*>;
|
||||
pFTRoot = new std::vector<ErsoEntryDir*>;
|
||||
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<DirectoryEntry *>(de), newPath);
|
||||
return SearchSectionForEntry(dynamic_cast<ErsoEntryDir *>(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<DirectoryEntry *>(e), newPath);
|
||||
return SearchSectionForEntry(dynamic_cast<ErsoEntryDir *>(e), newPath);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <boost/filesystem.hpp>
|
||||
#include <vector>
|
||||
#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<struct dataSection> *pDatSection = nullptr;
|
||||
MEMFILE rDatPtr = nullptr;
|
||||
|
||||
std::vector<DirectoryEntry*> *pFTRoot = nullptr;
|
||||
std::vector<ErsoEntryDir*> *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_ */
|
68
src/ErsoEntry.cpp
Normal file
68
src/ErsoEntry.cpp
Normal file
@ -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<ErsoEntry*>;
|
||||
}
|
||||
|
||||
ErsoEntryDir::ErsoEntryDir( std::string name, DAT_FILE_FLAGS fFlags ) {
|
||||
this->name = name;
|
||||
this->fFlags.raw = fFlags.raw;
|
||||
this->rootDir = false;
|
||||
vSubFiles = new std::vector<ErsoEntry*>;
|
||||
}
|
||||
|
||||
ErsoEntryDir::ErsoEntryDir( std::string name, DAT_FILE_FLAGS fFlags, ErsoEntry* hFileEntry ) {
|
||||
this->name = name;
|
||||
this->fFlags.raw = fFlags.raw;
|
||||
vSubFiles = new std::vector<ErsoEntry*>;
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -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 <RDI_Datatypes.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
#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<DatEntry*> getFiles() { return *vSubFiles; }
|
||||
void AddEntry( ErsoEntry* hFileEntry );
|
||||
std::vector<ErsoEntry*> getFiles() { return *vSubFiles; }
|
||||
|
||||
//std::string toString();
|
||||
bool isDirectory() { return true; }
|
||||
@ -86,9 +86,9 @@ public:
|
||||
|
||||
private:
|
||||
bool rootDir;
|
||||
std::vector<DatEntry*> *vSubFiles;
|
||||
std::vector<ErsoEntry*> *vSubFiles;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* DATENTRY_H_ */
|
||||
#endif /* ERSODATENTRY_HPP_ */
|
98
src/Krennic.cpp
Normal file
98
src/Krennic.cpp
Normal file
@ -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 <RSPModel.h>
|
||||
#include <RSPTerrain.h>
|
||||
#include <RSPTexture.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#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<ErsoEntryDir*>(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<std::string> 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<ErsoEntryDir*>(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<ErsoEntryDir*>(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 ) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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 <vector>
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "RDat.h"
|
||||
#include "datfiles/GenericFile.h"
|
||||
#include "datfiles/HMT.h"
|
||||
#include <FileHandler/Generic.h>
|
||||
#include <FileHandler/HMT.h>
|
||||
#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<std::string> listMusic;
|
||||
std::vector<std::string> 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_ */
|
@ -8,12 +8,12 @@
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include "../DatEntry.h"
|
||||
#include "GenericFile.h"
|
||||
#include <FileHandler/Generic.h>
|
||||
#include "ErsoEntry.hpp"
|
||||
|
||||
namespace RDI {
|
||||
|
||||
GenericFile::GenericFile( FileEntry& hDat ) {
|
||||
GenericFile::GenericFile( ErsoEntryFile& hDat ) {
|
||||
this->size = hDat.getSize();
|
||||
this->fileName = hDat.getName();
|
||||
this->fileExtension = "";
|
@ -7,13 +7,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "GenericFile.h"
|
||||
#include "HMT.h"
|
||||
#include <FileHandler/Generic.h>
|
||||
#include <FileHandler/HMT.h>
|
||||
|
||||
|
||||
namespace RDI {
|
||||
|
||||
HMT::HMT( FileEntry& hDat ): GenericFile( hDat ) {
|
||||
HMT::HMT( ErsoEntryFile& hDat ): GenericFile( hDat ) {
|
||||
this->fileExtension = "hmt";
|
||||
}
|
||||
|
@ -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 <RSPModel.h>
|
||||
#include <RSPTerrain.h>
|
||||
#include <RSPTexture.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
#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<DirectoryEntry*>(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<std::string> 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<DirectoryEntry*>(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<DirectoryEntry*>(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 ) {
|
||||
|
||||
}
|
||||
|
||||
}
|
60
src/RDI.cpp
60
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 <vector>
|
||||
#include <fstream>
|
||||
#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<DirectoryEntry *>(hRDat->getElement(boost::filesystem::path(path)));
|
||||
result = dynamic_cast<ErsoEntryDir *>(hErsoModule->getElement(boost::filesystem::path(path)));
|
||||
|
||||
if (result == nullptr) return 0;
|
||||
else return result->getSize();
|
||||
}
|
||||
|
||||
std::vector<std::string> RDI::getDirectoryElements( std::string path ) {
|
||||
DirectoryEntry* de = nullptr;
|
||||
ErsoEntryDir* de = nullptr;
|
||||
std::vector<std::string> elementsNameArray;
|
||||
elementsNameArray.clear();
|
||||
|
||||
if (!path.empty()) {
|
||||
de = dynamic_cast<DirectoryEntry *>(hRDat->getElement(boost::filesystem::path(path)));
|
||||
de = dynamic_cast<ErsoEntryDir *>(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<std::string> 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<std::string> RDI::getLevelsName( void ) {
|
||||
return hLegacyExp->getLevelsList();
|
||||
return hKrennicModule->getLevelsList();
|
||||
}
|
||||
|
||||
std::vector<std::string> RDI::getModelsName( void ) {
|
||||
return hLegacyExp->getModelsList();
|
||||
return hKrennicModule->getModelsList();
|
||||
}
|
||||
|
||||
std::vector<std::string> 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;
|
||||
}
|
||||
|
16
tools/ErsoDebug.cpp
Normal file
16
tools/ErsoDebug.cpp
Normal file
@ -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 <RDI.hpp>
|
||||
|
||||
|
||||
int main( int argc, char *argv[] ) {
|
||||
|
||||
return 0;
|
||||
}
|
16
tools/KrennicDebug.cpp
Normal file
16
tools/KrennicDebug.cpp
Normal file
@ -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 <RDI.hpp>
|
||||
|
||||
|
||||
int main( int argc, char *argv[] ) {
|
||||
|
||||
return 0;
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <RDI.h>
|
||||
#include <RDI.hpp>
|
||||
|
||||
|
||||
void PrintVirtualDirectoryContents( boost::filesystem::path, std::string );
|
||||
|
Loading…
x
Reference in New Issue
Block a user