diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 59fb084a8e..ce5965be12 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -40,6 +40,7 @@ add_component_dir (esm loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter + savedgame ) add_component_dir (misc diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index dd7ebfe932..5a5ef9f1cf 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -83,6 +83,9 @@ enum RecNameInts REC_STAT = 0x54415453, REC_WEAP = 0x50414557, + // format 0 - saved games + REC_SAVE = 0x45564153, + // format 1 REC_FILT = 0x544C4946 }; diff --git a/components/esm/savedgame.cpp b/components/esm/savedgame.cpp new file mode 100644 index 0000000000..a717c6469f --- /dev/null +++ b/components/esm/savedgame.cpp @@ -0,0 +1,36 @@ + +#include "savedgame.hpp" + +#include "esmreader.hpp" +#include "esmwriter.hpp" +#include "defs.hpp" + +unsigned int ESM::SavedGame::sRecordId = ESM::REC_SAVE; + +void ESM::SavedGame::load (ESMReader &esm) +{ + mPlayerName = esm.getHNString("PNAM"); + esm.getHNOT (mPlayerLevel, "PLEV"); + mPlayerClass = esm.getHNString("PCLA"); + mPlayerCell = esm.getHNString("PCEL"); + esm.getHNT (mInGameTime, "TSTM", 16); + esm.getHNT (mTimePlayed, "TIME"); + + while (esm.isNextSub ("DEPE")) + mContentFiles.push_back (esm.getHString()); +} + +void ESM::SavedGame::save (ESMWriter &esm) const +{ + esm.writeHNCString (mPlayerName, "PNAM"); + esm.writeHNT ("PLEV", mPlayerLevel); + esm.writeHNCString (mPlayerClass, "PCLA"); + esm.writeHNCString (mPlayerCell, "PCEL"); + esm.writeHNT ("TSTM", mInGameTime, 16); + esm.writeHNT ("TIME", mTimePlayed); + + for (std::vector::const_iterator iter (mContentFiles.begin()); + iter!=mContentFiles.end(); ++iter) + esm.writeHNCString (*iter, "DEPE"); + +} diff --git a/components/esm/savedgame.hpp b/components/esm/savedgame.hpp new file mode 100644 index 0000000000..ae8f79263d --- /dev/null +++ b/components/esm/savedgame.hpp @@ -0,0 +1,41 @@ +#ifndef OPENMW_ESM_SAVEDGAME_H +#define OPENMW_ESM_SAVEDGAME_H + +#include +#include + +namespace ESM +{ + class ESMReader; + class ESMWriter; + + // format 0, saved games only + + struct SavedGame + { + static unsigned int sRecordId; + + struct TimeStamp + { + float mGameHour; + int mDay; + int mMonth; + int mYear; + }; + + std::vector mContentFiles; + std::string mPlayerName; + int mPlayerLevel; + std::string mPlayerClass; + std::string mPlayerCell; + TimeStamp mInGameTime; + float mTimePlayed; + + /// \todo add field for screenshot + + void load (ESMReader &esm); + void save (ESMWriter &esm) const; + }; +} + +#endif