From 4f7dcd5ae57b767b1b23af02682b6671ede0468b Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 12 Sep 2022 01:25:44 +0200 Subject: [PATCH 1/2] Fix conversion to UTF8 for ESM4 Reader strings toUtf8 returns a string view to the input when input string is ASCII and nothing is written to the buffer which means output string of Reader::getStringImpl is not modified. Move input to the output string and resize it in this case. --- components/esm4/reader.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/esm4/reader.cpp b/components/esm4/reader.cpp index 450b86de0d..cc13f5db97 100644 --- a/components/esm4/reader.cpp +++ b/components/esm4/reader.cpp @@ -652,7 +652,12 @@ bool Reader::getStringImpl(std::string& str, std::size_t size, stream.read(input.data(), size); if (stream.gcount() == static_cast(size)) { - encoder->getUtf8(input, ToUTF8::BufferAllocationPolicy::FitToRequiredSize, str); + const std::string_view result = encoder->getUtf8(input, ToUTF8::BufferAllocationPolicy::FitToRequiredSize, str); + if (str.empty() && !result.empty()) + { + str = std::move(input); + str.resize(result.size()); + } return true; } } From a9826342b278d85e00e9f0bf81aa80308ca6c801 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 12 Sep 2022 01:33:13 +0200 Subject: [PATCH 2/2] Print ESM4 EditorId and Model by esmtool dump --- apps/esmtool/tes4.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/esmtool/tes4.cpp b/apps/esmtool/tes4.cpp index 815eb6dd34..2959b8145a 100644 --- a/apps/esmtool/tes4.cpp +++ b/apps/esmtool/tes4.cpp @@ -62,6 +62,24 @@ namespace EsmTool template constexpr bool hasFlags = HasFlags::value; + template > + struct HasEditorId : std::false_type {}; + + template + struct HasEditorId> : std::true_type {}; + + template + constexpr bool hasEditorId = HasEditorId::value; + + template > + struct HasModel : std::false_type {}; + + template + struct HasModel> : std::true_type {}; + + template + constexpr bool hasModel = HasModel::value; + template void readTypedRecord(const Params& params, ESM4::Reader& reader) { @@ -75,9 +93,13 @@ namespace EsmTool std::cout << "\n Record: " << ESM::NAME(reader.hdr().record.typeId).toStringView(); if constexpr (hasFormId) - std::cout << ' ' << value.mFormId; + std::cout << "\n FormId: " << value.mFormId; if constexpr (hasFlags) std::cout << "\n Record flags: " << recordFlags(value.mFlags); + if constexpr (hasEditorId) + std::cout << "\n EditorId: " << value.mEditorId; + if constexpr (hasModel) + std::cout << "\n Model: " << value.mModel; std::cout << '\n'; }