2023-04-04 07:58:49 +00:00
|
|
|
#include "loadgmst.hpp"
|
|
|
|
|
2023-05-30 17:49:03 +00:00
|
|
|
#include <cstdint>
|
2023-04-04 07:58:49 +00:00
|
|
|
#include <stdexcept>
|
2023-05-30 17:49:03 +00:00
|
|
|
#include <string>
|
2023-04-04 07:58:49 +00:00
|
|
|
|
|
|
|
#include "reader.hpp"
|
|
|
|
|
|
|
|
namespace ESM4
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2023-07-30 19:55:36 +00:00
|
|
|
GameSetting::Data readData(ESM::FormId formId, std::string_view editorId, Reader& reader)
|
2023-04-04 07:58:49 +00:00
|
|
|
{
|
|
|
|
if (editorId.empty())
|
2023-07-17 17:49:02 +00:00
|
|
|
{
|
|
|
|
reader.skipSubRecordData();
|
|
|
|
return std::monostate{};
|
|
|
|
}
|
2023-04-04 07:58:49 +00:00
|
|
|
const char type = editorId[0];
|
|
|
|
switch (type)
|
|
|
|
{
|
2023-05-17 16:35:55 +00:00
|
|
|
case 'b':
|
|
|
|
{
|
|
|
|
std::uint32_t value = 0;
|
|
|
|
reader.get(value);
|
|
|
|
return value != 0;
|
|
|
|
}
|
2023-04-04 07:58:49 +00:00
|
|
|
case 'i':
|
|
|
|
{
|
|
|
|
std::int32_t value = 0;
|
|
|
|
reader.get(value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
case 'f':
|
|
|
|
{
|
|
|
|
float value = 0;
|
|
|
|
reader.get(value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
std::string value;
|
|
|
|
reader.getZString(value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw std::runtime_error(
|
2023-04-07 00:14:32 +00:00
|
|
|
"Unsupported ESM4 GMST (" + formId.toString() + ") data type: " + std::string(editorId));
|
2023-04-04 07:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameSetting::load(Reader& reader)
|
|
|
|
{
|
2023-07-30 19:55:36 +00:00
|
|
|
mId = reader.getFormIdFromHeader();
|
2023-04-04 07:58:49 +00:00
|
|
|
mFlags = reader.hdr().record.flags;
|
|
|
|
|
|
|
|
while (reader.getSubRecordHeader())
|
|
|
|
{
|
|
|
|
const ESM4::SubRecordHeader& subHdr = reader.subRecordHeader();
|
|
|
|
switch (subHdr.typeId)
|
|
|
|
{
|
|
|
|
case ESM4::SUB_EDID:
|
|
|
|
reader.getZString(mEditorId);
|
|
|
|
break;
|
|
|
|
case ESM4::SUB_DATA:
|
2023-07-30 19:55:36 +00:00
|
|
|
mData = readData(mId, mEditorId, reader);
|
2023-04-04 07:58:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
2023-04-07 00:14:32 +00:00
|
|
|
throw std::runtime_error(
|
2023-07-30 19:55:36 +00:00
|
|
|
"Unknown ESM4 GMST (" + mId.toString() + ") subrecord " + ESM::printName(subHdr.typeId));
|
2023-04-04 07:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|