2013-11-19 09:51:30 +00:00
|
|
|
#include "savedgame.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
2024-02-27 19:47:46 +00:00
|
|
|
#include <components/misc/algorithm.hpp>
|
|
|
|
#include <components/misc/concepts.hpp>
|
2024-01-11 18:05:37 +00:00
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
2024-02-27 19:47:46 +00:00
|
|
|
template <Misc::SameAsWithoutCvref<EpochTimeStamp> T>
|
|
|
|
void decompose(T&& v, const auto& f)
|
|
|
|
{
|
|
|
|
f(v.mGameHour, v.mDay, v.mMonth, v.mYear);
|
|
|
|
}
|
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
void SavedGame::load(ESMReader& esm)
|
2013-11-19 09:51:30 +00:00
|
|
|
{
|
2013-12-03 13:30:18 +00:00
|
|
|
mPlayerName = esm.getHNString("PLNA");
|
|
|
|
esm.getHNOT(mPlayerLevel, "PLLE");
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2023-02-12 18:36:56 +00:00
|
|
|
mPlayerClassId = esm.getHNORefId("PLCL");
|
2014-03-27 21:32:42 +00:00
|
|
|
mPlayerClassName = esm.getHNOString("PLCN");
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2023-03-26 11:23:19 +00:00
|
|
|
if (esm.getFormatVersion() <= ESM::MaxSavedGameCellNameAsRefIdFormatVersion)
|
2023-03-22 21:57:52 +00:00
|
|
|
mPlayerCellName = esm.getHNRefId("PLCE").toString();
|
|
|
|
else
|
|
|
|
mPlayerCellName = esm.getHNString("PLCE");
|
2024-02-27 19:47:46 +00:00
|
|
|
esm.getNamedComposite("TSTM", mInGameTime);
|
2013-11-19 09:51:30 +00:00
|
|
|
esm.getHNT(mTimePlayed, "TIME");
|
2013-11-24 14:19:56 +00:00
|
|
|
mDescription = esm.getHNString("DESC");
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2013-11-19 09:51:30 +00:00
|
|
|
while (esm.isNextSub("DEPE"))
|
|
|
|
mContentFiles.push_back(esm.getHString());
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2014-01-24 16:49:16 +00:00
|
|
|
esm.getSubNameIs("SCRN");
|
|
|
|
esm.getSubHeader();
|
|
|
|
mScreenshot.resize(esm.getSubSize());
|
Fix reference binding to null
/usr/include/c++/10.2.0/bits/stl_vector.h:1046:34: runtime error: reference binding to null pointer of type 'value_type'
#0 0x55e37f50008a in std::vector<char, std::allocator<char> >::operator[](unsigned long) /usr/include/c++/10.2.0/bits/stl_vector.h:1046
#1 0x55e37f50008a in ESM::SavedGame::load(ESM::ESMReader&) /home/elsid/dev/openmw/components/esm/savedgame.cpp:28
#2 0x55e37e726139 in MWState::Character::addSlot(boost::filesystem::path const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/elsid/dev/openmw/apps/openmw/mwstate/character.cpp:31
#3 0x55e37e742b39 in MWState::Character::Character(boost::filesystem::path const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/elsid/dev/openmw/apps/openmw/mwstate/character.cpp:88
#4 0x55e37e7006e1 in MWState::CharacterManager::CharacterManager(boost::filesystem::path const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/elsid/dev/openmw/apps/openmw/mwstate/charactermanager.cpp:25
#5 0x55e37e6d4140 in MWState::StateManager::StateManager(boost::filesystem::path const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/elsid/dev/openmw/apps/openmw/mwstate/statemanagerimp.cpp:90
#6 0x55e37e82595a in OMW::Engine::prepareEngine(Settings::Manager&) /home/elsid/dev/openmw/apps/openmw/engine.cpp:641
#7 0x55e37e8439fd in OMW::Engine::go() /home/elsid/dev/openmw/apps/openmw/engine.cpp:867
#8 0x55e37e782760 in runApplication(int, char**) /home/elsid/dev/openmw/apps/openmw/main.cpp:289
#9 0x55e37f6483c3 in wrapApplication(int (*)(int, char**), int, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/elsid/dev/openmw/components/debug/debugging.cpp:200
#10 0x55e37ba8e3fe in main /home/elsid/dev/openmw/apps/openmw/main.cpp:301
#11 0x7f013e845151 in __libc_start_main (/usr/lib/libc.so.6+0x28151)
#12 0x55e37baa0e3d in _start (/home/elsid/dev/openmw/build/gcc/ubsan/openmw+0x6c11e3d)
2021-01-09 20:38:56 +00:00
|
|
|
esm.getExact(mScreenshot.data(), mScreenshot.size());
|
2023-10-13 08:05:32 +00:00
|
|
|
|
|
|
|
esm.getHNOT(mCurrentDay, "CDAY");
|
|
|
|
esm.getHNOT(mCurrentHealth, "CHLT");
|
|
|
|
esm.getHNOT(mMaximumHealth, "MHLT");
|
2013-11-19 09:51:30 +00:00
|
|
|
}
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
void SavedGame::save(ESMWriter& esm) const
|
2013-11-19 09:51:30 +00:00
|
|
|
{
|
2013-12-03 13:30:18 +00:00
|
|
|
esm.writeHNString("PLNA", mPlayerName);
|
|
|
|
esm.writeHNT("PLLE", mPlayerLevel);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2014-03-27 21:32:42 +00:00
|
|
|
if (!mPlayerClassId.empty())
|
2023-02-12 18:36:56 +00:00
|
|
|
esm.writeHNRefId("PLCL", mPlayerClassId);
|
2014-03-27 21:32:42 +00:00
|
|
|
else
|
|
|
|
esm.writeHNString("PLCN", mPlayerClassName);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2023-03-22 21:57:52 +00:00
|
|
|
esm.writeHNString("PLCE", mPlayerCellName);
|
2024-02-27 19:47:46 +00:00
|
|
|
esm.writeNamedComposite("TSTM", mInGameTime);
|
2013-11-19 09:51:30 +00:00
|
|
|
esm.writeHNT("TIME", mTimePlayed);
|
2013-11-26 08:56:08 +00:00
|
|
|
esm.writeHNString("DESC", mDescription);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2024-02-27 19:47:46 +00:00
|
|
|
for (const std::string& dependency : mContentFiles)
|
|
|
|
esm.writeHNString("DEPE", dependency);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2014-01-24 16:49:16 +00:00
|
|
|
esm.startSubRecord("SCRN");
|
2022-09-02 04:04:02 +00:00
|
|
|
esm.write(mScreenshot.data(), mScreenshot.size());
|
2014-01-24 16:49:16 +00:00
|
|
|
esm.endRecord("SCRN");
|
2023-10-13 08:05:32 +00:00
|
|
|
|
|
|
|
esm.writeHNT("CDAY", mCurrentDay);
|
|
|
|
esm.writeHNT("CHLT", mCurrentHealth);
|
|
|
|
esm.writeHNT("MHLT", mMaximumHealth);
|
2013-11-19 09:51:30 +00:00
|
|
|
}
|
2022-04-11 22:18:39 +00:00
|
|
|
|
2023-11-16 07:41:19 +00:00
|
|
|
std::vector<std::string_view> SavedGame::getMissingContentFiles(
|
|
|
|
const std::vector<std::string>& allContentFiles) const
|
|
|
|
{
|
|
|
|
std::vector<std::string_view> missingFiles;
|
|
|
|
for (const std::string& contentFile : mContentFiles)
|
|
|
|
{
|
2024-01-11 18:05:37 +00:00
|
|
|
auto it = std::find_if(allContentFiles.begin(), allContentFiles.end(),
|
|
|
|
[&](const std::string& file) { return Misc::StringUtils::ciEqual(file, contentFile); });
|
|
|
|
if (it == allContentFiles.end())
|
2023-11-16 07:41:19 +00:00
|
|
|
{
|
|
|
|
missingFiles.emplace_back(contentFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return missingFiles;
|
|
|
|
}
|
2022-04-11 22:18:39 +00:00
|
|
|
}
|