mirror of https://github.com/OpenMW/openmw.git
Adding basic save functions to all record types.
parent
8bf9b371c7
commit
ba602929ef
@ -0,0 +1,102 @@
|
||||
#ifndef _ESM_COMMON_H
|
||||
#define _ESM_COMMON_H
|
||||
|
||||
#include <libs/platform/stdint.h>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
enum Version
|
||||
{
|
||||
VER_12 = 0x3f99999a,
|
||||
VER_13 = 0x3fa66666
|
||||
};
|
||||
|
||||
enum FileType
|
||||
{
|
||||
FT_ESP = 0, // Plugin
|
||||
FT_ESM = 1, // Master
|
||||
FT_ESS = 32 // Savegame
|
||||
};
|
||||
|
||||
// Used to mark special files. The original ESM files are given
|
||||
// special treatment in a few places, most noticably in loading and
|
||||
// filtering out "dirtly" GMST entries correctly.
|
||||
enum SpecialFile
|
||||
{
|
||||
SF_Other,
|
||||
SF_Morrowind,
|
||||
SF_Tribunal,
|
||||
SF_Bloodmoon
|
||||
};
|
||||
|
||||
/* A structure used for holding fixed-length strings. In the case of
|
||||
LEN=4, it can be more efficient to match the string as a 32 bit
|
||||
number, therefore the struct is implemented as a union with an int.
|
||||
*/
|
||||
template <int LEN>
|
||||
union NAME_T
|
||||
{
|
||||
char name[LEN];
|
||||
int32_t val;
|
||||
|
||||
bool operator==(const char *str)
|
||||
{
|
||||
for(int i=0; i<LEN; i++)
|
||||
if(name[i] != str[i]) return false;
|
||||
else if(name[i] == 0) return true;
|
||||
return str[LEN] == 0;
|
||||
}
|
||||
bool operator!=(const char *str) { return !((*this)==str); }
|
||||
|
||||
bool operator==(const std::string &str)
|
||||
{
|
||||
return (*this) == str.c_str();
|
||||
}
|
||||
bool operator!=(const std::string &str) { return !((*this)==str); }
|
||||
|
||||
bool operator==(int v) { return v == val; }
|
||||
bool operator!=(int v) { return v != val; }
|
||||
|
||||
std::string toString() const { return std::string(name, strnlen(name, LEN)); }
|
||||
};
|
||||
|
||||
typedef NAME_T<4> NAME;
|
||||
typedef NAME_T<32> NAME32;
|
||||
typedef NAME_T<64> NAME64;
|
||||
typedef NAME_T<256> NAME256;
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
/// File header data for all ES files
|
||||
struct HEDRstruct
|
||||
{
|
||||
/* File format version. This is actually a float, the supported
|
||||
versions are 1.2 and 1.3. These correspond to:
|
||||
1.2 = 0x3f99999a and 1.3 = 0x3fa66666
|
||||
*/
|
||||
int version;
|
||||
int type; // 0=esp, 1=esm, 32=ess
|
||||
NAME32 author; // Author's name
|
||||
NAME256 desc; // File description
|
||||
int records; // Number of records? Not used.
|
||||
};
|
||||
|
||||
// Defines another files (esm or esp) that this file depends upon.
|
||||
struct MasterData
|
||||
{
|
||||
std::string name;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
// Data that is only present in save game files
|
||||
struct SaveData
|
||||
{
|
||||
float pos[6]; // Player position and rotation
|
||||
NAME64 cell; // Cell name
|
||||
float unk2; // Unknown value - possibly game time?
|
||||
NAME32 player; // Player name
|
||||
};
|
||||
#pragma pack(pop)
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,28 @@
|
||||
#include "esm_writer.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
|
||||
void ESMWriter::writeHNString(const std::string& name, const std::string& data)
|
||||
{
|
||||
writeName(name);
|
||||
writeHString(data);
|
||||
}
|
||||
|
||||
void ESMWriter::writeHString(const std::string& data)
|
||||
{
|
||||
writeT<int>(data.size()-1);
|
||||
write(data.c_str(), data.size()-1);
|
||||
}
|
||||
|
||||
void ESMWriter::writeName(const std::string& name)
|
||||
{
|
||||
write(name.c_str(), name.size()-1);
|
||||
}
|
||||
|
||||
void ESMWriter::write(const char* data, int size)
|
||||
{
|
||||
m_stream.write(data, size);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
#ifndef _ESM_WRITER_H
|
||||
#define _ESM_WRITER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
#include "esm_common.hpp"
|
||||
|
||||
namespace ESM {
|
||||
|
||||
class ESMWriter
|
||||
{
|
||||
public:
|
||||
void writeHNString(const std::string& name, const std::string& data);
|
||||
void writeHNOString(const std::string& name, const std::string& data)
|
||||
{
|
||||
if (!data.empty())
|
||||
writeHNString(name, data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writeHNT(const std::string& name, const T& data)
|
||||
{
|
||||
writeName(name);
|
||||
writeT(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writeHNT(const std::string& name, const T& data, int size)
|
||||
{
|
||||
assert(sizeof(T) == size);
|
||||
writeHNT(name, data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writeHT(const T& data)
|
||||
{
|
||||
writeT((unsigned int)sizeof(T));
|
||||
writeT(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writeHT(const T& data, int size)
|
||||
{
|
||||
assert(sizeof(T) == size);
|
||||
writeHT(data);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writeT(const T& data)
|
||||
{
|
||||
write((char*)&data, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void writeT(const T& data, int size)
|
||||
{
|
||||
assert(sizeof(T) == size);
|
||||
writeT(data);
|
||||
}
|
||||
|
||||
void writeHString(const std::string& data);
|
||||
void writeName(const std::string& data);
|
||||
void write(const char* data, int size);
|
||||
|
||||
private:
|
||||
std::ostream m_stream;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue