1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-17 10:21:11 +00:00

Fix NiStringPalette loading

This commit is contained in:
Alexei Kotov 2023-02-09 20:58:08 +03:00
parent a41cbfb349
commit a4ddf443ed
2 changed files with 12 additions and 1 deletions

View File

@ -470,7 +470,7 @@ namespace Nif
void NiStringPalette::read(NIFStream* nif) void NiStringPalette::read(NIFStream* nif)
{ {
palette = nif->getString(); palette = nif->getStringPalette();
if (nif->getUInt() != palette.size()) if (nif->getUInt() != palette.size())
Log(Debug::Warning) << "NIFFile Warning: Failed size check in NiStringPalette. File: " Log(Debug::Warning) << "NIFFile Warning: Failed size check in NiStringPalette. File: "
<< nif->getFile().getFilename(); << nif->getFile().getFilename();

View File

@ -169,6 +169,17 @@ namespace Nif
return result; return result;
} }
/// Read a sequence of null-terminated strings
std::string getStringPalette()
{
size_t size = readLittleEndianType<uint32_t>(inp);
std::string str(size, '\0');
inp->read(str.data(), size);
if (inp->bad())
throw std::runtime_error("Failed to read string palette of " + std::to_string(size) + " chars");
return str;
}
void getChars(std::vector<char>& vec, size_t size) void getChars(std::vector<char>& vec, size_t size)
{ {
vec.resize(size); vec.resize(size);