Added data struct template

This commit is contained in:
JackCarterSmith 2022-09-16 19:56:43 +02:00
parent dd48841d7f
commit 494bb6246e
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
6 changed files with 184 additions and 26 deletions

View File

@ -25,15 +25,15 @@
#if defined(RDI_DLL)
# if defined(WIN32)
# if defined(RDI_DLLBUILD)
# define RDI_EXTERN extern RDI_ABI_EXPORT
# define RDI_EXTERN RDI_ABI_EXPORT
# else
# define RDI_EXTERN extern RDI_ABI_IMPORT
# define RDI_EXTERN RDI_ABI_IMPORT
# endif
# endif
#endif
#ifndef RDI_EXTERN
# define RDI_EXTERN extern
# define RDI_EXTERN
#endif
///////////////////////////////////////////////////////////////////////////////
@ -42,11 +42,40 @@
namespace RDI
{
/**
* @brief Get the current library version.
* @return Char array of the version, escape char included.
*/
RDI_EXTERN const char* getVersion( void );
class RDI_EXTERN RDI {
private:
std::string libVersion;
std::string workingDir = ".";
public:
RDI();
~RDI();
/**
* @brief Get the current library version.
* @return String of the version.
*/
inline std::string getLibVersion() {
return libVersion;
}
/**
* @brief Get the current working directory of the library instance.
* @return Path string of the current working directory.
*/
std::string getWorkingDirectory() {
return workingDir;
}
/**
* @brief Set the current working directory of the library instance.
* @param[in] newPath Path string without final slash.
*/
void setWorkingDirectory( std::string newPath ) {
workingDir = newPath;
}
};
/**
* @brief Search for Rogue data file, try to open it and map it in memory.

View File

@ -22,12 +22,20 @@ using namespace std;
using RDI::RDat;
namespace RDI {
RDI::RDI() {
this->libVersion = PRG_VERSION;
}
}
/*
* Libs interface
*/
inline const char* RDI::getVersion( void ) {
return PRG_VERSION;
}
unsigned short OpenRogueDat( void ) {
return 0;

View File

@ -7,8 +7,10 @@
*
*/
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include "data_struct.h"
#include "RDat.h"
using namespace std;
@ -27,7 +29,7 @@ RDat::RDat( string fPath ) {
rdf.open(datFile, ios::in | ios::binary);
if (rdf.is_open()) {
size = rdf.tellg();
rDatPtr = new char[size];
rDatPtr = (MEMFILE)malloc(size);
rdf.seekg(0, ios::beg);
rdf.read(rDatPtr, size);
rdf.close();

View File

@ -7,27 +7,29 @@
*
*/
#ifndef SRC_RDAT_H_
#define SRC_RDAT_H_
#ifndef RDAT_H_
#define RDAT_H_
namespace RDI {
typedef char* MEMFILE;
typedef char* MEMFILE;
class RDat {
private:
MEMFILE rDatPtr = nullptr;
public:
RDat( std::string fPath );
virtual ~RDat();
class RDat {
private:
MEMFILE rDatPtr = nullptr;
MEMFILE getRDat() {
return rDatPtr;
}
public:
RDat( std::string fPath );
virtual ~RDat();
};
MEMFILE getRDat() {
return rDatPtr;
}
};
} /* namespace RDI */
#endif /* SRC_RDAT_H_ */
#endif /* RDAT_H_ */

47
src/bundle_struct.h Normal file
View File

@ -0,0 +1,47 @@
/**
* @file bundle_struct.h
* @date 16/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Bundle (000/001) file mapping definition.
*
*/
#ifndef BUNDLE_STRUCT_H_
#define BUNDLE_STRUCT_H_
#ifndef PACK
# if defined(_MSC_VER)
# define PACK
# elif defined(__GNUC__)
# define PACK __attribute__((packed))
# endif
#endif
namespace RDI {
////////////////////////////////////////////////////////////////////////////
// Declaration of Memory Mapped Structure
// Caution: the place of variable is important for correct mapping!
////////////////////////////////////////////////////////////////////////////
#if defined(_MSC_VER)
#pragma pack(push, 1)
#endif
typedef struct PACK file_header {
unsigned int datas_offset;
} T_FILE_HEADER;
typedef struct PACK dat_section {
unsigned int file_headers_offset;
} T_DAT_SECTION;
#if defined(_MSC_VER)
#pragma pack(pop)
#endif
}
#endif /* BUNDLE_STRUCT_H_ */

70
src/data_struct.h Normal file
View File

@ -0,0 +1,70 @@
/**
* @file data_struct.h
* @date 16/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Data file mapping definition.
*
*/
#ifndef DATA_STRUCT_H_
#define DATA_STRUCT_H_
#ifndef PACK
# if defined(_MSC_VER)
# define PACK
# elif defined(__GNUC__)
# define PACK __attribute__((packed))
# endif
#endif
namespace RDI {
////////////////////////////////////////////////////////////////////////////
// Declaration of Memory Mapped Structure
// Caution: the place of variable is important for correct mapping!
////////////////////////////////////////////////////////////////////////////
#if defined(_MSC_VER)
#pragma pack(push, 1)
#endif
/*
* DATA.DAT content type
*/
typedef struct PACK file_header {
unsigned int datas_offset;
unsigned int datas_size; // If file is directory, equal to sum of it's file.
unsigned int reserved0; // 0xFFFFFFFF
unsigned short flags;
unsigned short dir_entries_size; // If directory = sum of files entry size + itself, 0 if standard file.
char name[16]; // File extension is UPPERCASE, separated of file name by '_'.
} T_FILE_HEADER;
typedef struct PACK dat_section {
unsigned int file_headers_offset;
unsigned int file_headers_size;
unsigned char files_datas; // Should be used as start pointer for memcpy.
} T_DAT_SECTION;
/*
* DATA.HDR content type
* Entries are in a row, test for EOF.
*/
typedef struct PACK hdr_entry {
char section_name[16];
unsigned int reserved0; // 12B of zeros
unsigned int reserved1;
unsigned int reserved2;
unsigned int section_offset;
} T_HDR_ENTRY;
#if defined(_MSC_VER)
#pragma pack(pop)
#endif
}
#endif /* DATA_STRUCT_H_ */