diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 3e5c6aa5d..6d2b59ad9 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -357,10 +357,10 @@ int load(Arguments& info) EsmTool::RecordBase *record = EsmTool::RecordBase::create(n); if (record == 0) { - if (std::find(skipped.begin(), skipped.end(), n.val) == skipped.end()) + if (std::find(skipped.begin(), skipped.end(), n.intval) == skipped.end()) { std::cout << "Skipping " << n.toString() << " records." << std::endl; - skipped.push_back(n.val); + skipped.push_back(n.intval); } esm.skipRecord(); @@ -392,7 +392,7 @@ int load(Arguments& info) record->print(); } - if (record->getType().val == ESM::REC_CELL && loadCells && interested) + if (record->getType().intval == ESM::REC_CELL && loadCells && interested) { loadCell(record->cast()->get(), esm, info); } @@ -405,7 +405,7 @@ int load(Arguments& info) { delete record; } - ++info.data.mRecordStats[n.val]; + ++info.data.mRecordStats[n.intval]; } } catch(std::exception &e) { @@ -448,14 +448,13 @@ int clone(Arguments& info) std::cout << "Loaded " << recordCount << " records:" << std::endl << std::endl; - ESM::NAME name; - int i = 0; typedef std::map Stats; Stats &stats = info.data.mRecordStats; for (Stats::iterator it = stats.begin(); it != stats.end(); ++it) { - name.val = it->first; + ESM::NAME name; + name.intval = it->first; int amount = it->second; std::cout << std::setw(digitCount) << amount << " " << name.toString() << " "; @@ -488,12 +487,12 @@ int clone(Arguments& info) for (Records::iterator it = records.begin(); it != records.end() && i > 0; ++it) { EsmTool::RecordBase *record = *it; - name.val = record->getType().val; + const ESM::NAME& typeName = record->getType(); - esm.startRecord(name.toString(), record->getFlags()); + esm.startRecord(typeName.toString(), record->getFlags()); record->save(esm); - if (name.val == ESM::REC_CELL) { + if (typeName.intval == ESM::REC_CELL) { ESM::Cell *ptr = &record->cast()->get(); if (!info.data.mCellRefs[ptr].empty()) { typedef std::deque > RefList; @@ -505,7 +504,7 @@ int clone(Arguments& info) } } - esm.endRecord(name.toString()); + esm.endRecord(typeName.toString()); saved++; int perc = (int)((saved / (float)recordCount)*100); diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index d7cbea73b..2382612a4 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -179,7 +179,7 @@ RecordBase::create(ESM::NAME type) { RecordBase *record = 0; - switch (type.val) { + switch (type.intval) { case ESM::REC_ACTI: { record = new EsmTool::Record; diff --git a/apps/essimporter/importer.cpp b/apps/essimporter/importer.cpp index 3d94f2b90..f17db309f 100644 --- a/apps/essimporter/importer.cpp +++ b/apps/essimporter/importer.cpp @@ -322,14 +322,14 @@ namespace ESSImport ESM::NAME n = esm.getRecName(); esm.getRecHeader(); - std::map >::iterator it = converters.find(n.val); + std::map >::iterator it = converters.find(n.intval); if (it != converters.end()) { it->second->read(esm); } else { - if (unknownRecords.insert(n.val).second) + if (unknownRecords.insert(n.intval).second) { std::ios::fmtflags f(std::cerr.flags()); std::cerr << "unknown record " << n.toString() << " (0x" << std::hex << esm.getFileOffset() << ")" << std::endl; diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 5c81d3b08..70c6d5d7e 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -942,7 +942,7 @@ bool CSMWorld::Data::continueLoading (CSMDoc::Messages& messages) bool unhandledRecord = false; - switch (n.val) + switch (n.intval) { case ESM::REC_GLOB: mGlobals.load (*mReader, mBase); break; case ESM::REC_GMST: mGmsts.load (*mReader, mBase); break; diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index eff7167de..e828a7f4e 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -1187,7 +1187,7 @@ namespace CSMWorld std::vector& list = container.mInventory.mList; - ESM::ContItem newRow = {0, {""}}; + ESM::ContItem newRow = ESM::ContItem(); if (position >= (int)list.size()) list.push_back(newRow); diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index cb3b4ca22..a8639b94b 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -385,7 +385,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str ESM::NAME n = reader.getRecName(); reader.getRecHeader(); - switch (n.val) + switch (n.intval) { case ESM::REC_SAVE: { @@ -405,12 +405,12 @@ void MWState::StateManager::loadGame (const Character *character, const std::str case ESM::REC_JOUR_LEGACY: case ESM::REC_QUES: - MWBase::Environment::get().getJournal()->readRecord (reader, n.val); + MWBase::Environment::get().getJournal()->readRecord (reader, n.intval); break; case ESM::REC_DIAS: - MWBase::Environment::get().getDialogueManager()->readRecord (reader, n.val); + MWBase::Environment::get().getDialogueManager()->readRecord (reader, n.intval); break; case ESM::REC_ALCH: @@ -433,7 +433,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str case ESM::REC_ENAB: case ESM::REC_LEVC: case ESM::REC_LEVI: - MWBase::Environment::get().getWorld()->readRecord(reader, n.val, contentFileMap); + MWBase::Environment::get().getWorld()->readRecord(reader, n.intval, contentFileMap); break; case ESM::REC_CAM_: @@ -442,7 +442,7 @@ void MWState::StateManager::loadGame (const Character *character, const std::str case ESM::REC_GSCR: - MWBase::Environment::get().getScriptManager()->getGlobalScripts().readRecord (reader, n.val); + MWBase::Environment::get().getScriptManager()->getGlobalScripts().readRecord (reader, n.intval); break; case ESM::REC_GMAP: @@ -450,13 +450,13 @@ void MWState::StateManager::loadGame (const Character *character, const std::str case ESM::REC_ASPL: case ESM::REC_MARK: - MWBase::Environment::get().getWindowManager()->readRecord(reader, n.val); + MWBase::Environment::get().getWindowManager()->readRecord(reader, n.intval); break; case ESM::REC_DCOU: case ESM::REC_STLN: - MWBase::Environment::get().getMechanicsManager()->readRecord(reader, n.val); + MWBase::Environment::get().getMechanicsManager()->readRecord(reader, n.intval); break; default: diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 7a1f222c7..4a1763d0a 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -74,10 +74,10 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) esm.getRecHeader(); // Look up the record type. - std::map::iterator it = mStores.find(n.val); + std::map::iterator it = mStores.find(n.intval); if (it == mStores.end()) { - if (n.val == ESM::REC_INFO) { + if (n.intval == ESM::REC_INFO) { if (dialogue) { dialogue->readInfo(esm, esm.getIndex() != 0); @@ -87,12 +87,12 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) std::cerr << "error: info record without dialog" << std::endl; esm.skipRecord(); } - } else if (n.val == ESM::REC_MGEF) { + } else if (n.intval == ESM::REC_MGEF) { mMagicEffects.load (esm); - } else if (n.val == ESM::REC_SKIL) { + } else if (n.intval == ESM::REC_SKIL) { mSkills.load (esm); } - else if (n.val==ESM::REC_FILT || n.val == ESM::REC_DBGP) + else if (n.intval==ESM::REC_FILT || n.intval == ESM::REC_DBGP) { // ignore project file only records esm.skipRecord(); @@ -110,7 +110,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) continue; } - if (n.val==ESM::REC_DIAL) { + if (n.intval==ESM::REC_DIAL) { dialogue = const_cast(mDialogs.find(id.mId)); } else { dialogue = 0; diff --git a/apps/openmw_test_suite/CMakeLists.txt b/apps/openmw_test_suite/CMakeLists.txt index 2300f97a3..24ea1835a 100644 --- a/apps/openmw_test_suite/CMakeLists.txt +++ b/apps/openmw_test_suite/CMakeLists.txt @@ -9,6 +9,8 @@ if (GTEST_FOUND) mwworld/test_store.cpp mwdialogue/test_keywordsearch.cpp + + esm/test_fixed_string.cpp ) source_group(apps\\openmw_test_suite FILES openmw_test_suite.cpp ${UNITTEST_SRC_FILES}) diff --git a/apps/openmw_test_suite/esm/test_fixed_string.cpp b/apps/openmw_test_suite/esm/test_fixed_string.cpp new file mode 100644 index 000000000..59dd7fe66 --- /dev/null +++ b/apps/openmw_test_suite/esm/test_fixed_string.cpp @@ -0,0 +1,75 @@ +#include +#include "components/esm/esmcommon.hpp" + +TEST(EsmFixedString, operator__eq_ne) +{ + { + SCOPED_TRACE("asdc == asdc"); + ESM::NAME name; + name.assign("asdc"); + char s[4] = {'a', 's', 'd', 'c'}; + std::string ss(s, 4); + + EXPECT_TRUE(name == s); + EXPECT_TRUE(name == ss.c_str()); + EXPECT_TRUE(name == ss); + } + { + SCOPED_TRACE("asdc == asdcx"); + ESM::NAME name; + name.assign("asdc"); + char s[5] = {'a', 's', 'd', 'c', 'x'}; + std::string ss(s, 5); + + EXPECT_TRUE(name != s); + EXPECT_TRUE(name != ss.c_str()); + EXPECT_TRUE(name != ss); + } + { + SCOPED_TRACE("asdc == asdc[NULL]"); + ESM::NAME name; + name.assign("asdc"); + char s[5] = {'a', 's', 'd', 'c', '\0'}; + std::string ss(s, 5); + + EXPECT_TRUE(name == s); + EXPECT_TRUE(name == ss.c_str()); + EXPECT_TRUE(name == ss); + } +} + +TEST(EsmFixedString, empty_strings) +{ + { + SCOPED_TRACE("4 bytes"); + ESM::NAME empty = ESM::NAME(); + EXPECT_TRUE(empty == ""); + EXPECT_TRUE(empty == static_cast(0)); + EXPECT_TRUE(empty != "some string"); + EXPECT_TRUE(empty != static_cast(42)); + } + { + SCOPED_TRACE("32 bytes"); + ESM::NAME32 empty = ESM::NAME32(); + EXPECT_TRUE(empty == ""); + EXPECT_TRUE(empty != "some string"); + } +} + +TEST(EsmFixedString, struct_size) +{ + ASSERT_EQ(4, sizeof(ESM::NAME)); + ASSERT_EQ(32, sizeof(ESM::NAME32)); + ASSERT_EQ(64, sizeof(ESM::NAME64)); + ASSERT_EQ(256, sizeof(ESM::NAME256)); +} + +TEST(EsmFixedString, DISABLED_is_pod) +{ + /* TODO: enable in C++11 + * ASSERT_TRUE(std::is_pod::value); + * ASSERT_TRUE(std::is_pod::value); + * ASSERT_TRUE(std::is_pod::value); + * ASSERT_TRUE(std::is_pod::value); + */ +} diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index 14fb14dd4..74d45bb0c 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -62,7 +62,7 @@ void ESM::CellRef::loadData(ESMReader &esm, bool &isDeleted) while (!isLoaded && esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'U','N','A','M'>::value: esm.getHT(mReferenceBlocked); diff --git a/components/esm/debugprofile.cpp b/components/esm/debugprofile.cpp index 66e338d0c..17249d8a3 100644 --- a/components/esm/debugprofile.cpp +++ b/components/esm/debugprofile.cpp @@ -13,7 +13,7 @@ void ESM::DebugProfile::load (ESMReader& esm, bool &isDeleted) while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/esmcommon.hpp b/components/esm/esmcommon.hpp index d90a3444d..d635ba6df 100644 --- a/components/esm/esmcommon.hpp +++ b/components/esm/esmcommon.hpp @@ -15,43 +15,98 @@ enum Version VER_13 = 0x3fa66666 }; -/* A structure used for holding fixed-length strings. In the case of - LEN=4, it can be more efficient to match the string as a 32 bit - number, therefore the struct is implemented as a union with an int. - */ -template -union NAME_T + +// CRTP for FIXED_STRING class, a structure used for holding fixed-length strings +template< template class DERIVED, size_t SIZE> +class FIXED_STRING_BASE { - char name[LEN]; - uint32_t val; + /* The following methods must be implemented in derived classes: + * char const* ro_data() const; // return pointer to ro buffer + * char* rw_data(); // return pointer to rw buffer + */ +public: + enum { size = SIZE }; - bool operator==(const char *str) const - { - for(int i=0; i + bool operator==(char const (&str)[OTHER_SIZE]) const + { + size_t other_len = strnlen(str, OTHER_SIZE); + if (other_len != this->length()) + return false; + return std::strncmp(self()->ro_data(), str, size) == 0; + } + bool operator==(const char* const str) const + { + char const* const data = self()->ro_data(); + for(size_t i = 0; i < size; ++i) + { + if(data[i] != str[i]) return false; + else if(data[i] == '\0') return true; + } + return str[size] == '\0'; + } + bool operator!=(const char* const str) const { return !( (*this) == str ); } + + bool operator==(const std::string& str) const + { + return (*this) == str.c_str(); + } + bool operator!=(const std::string& str) const { return !( (*this) == str ); } + + size_t data_size() const { return size; } + size_t length() const { return strnlen(self()->ro_data(), size); } + std::string toString() const { return std::string(self()->ro_data(), this->length()); } + + void assign(const std::string& value) { std::strncpy(self()->rw_data(), value.c_str(), size); } + void clear() { this->assign(""); } +private: + DERIVED const* self() const + { + return static_cast const*>(this); + } + + // write the non-const version in terms of the const version + // Effective C++ 3rd ed., Item 3 (p. 24-25) + DERIVED* self() + { + return const_cast*>(static_cast(this)->self()); + } +}; + +// Generic implementation +template +struct FIXED_STRING : public FIXED_STRING_BASE +{ + char data[SIZE]; + + char const* ro_data() const { return data; } + char* rw_data() { return data; } +}; + +// In the case of SIZE=4, it can be more efficient to match the string +// as a 32 bit number, therefore the struct is implemented as a union with an int. +template <> +struct FIXED_STRING<4> : public FIXED_STRING_BASE +{ + union { + char data[4]; + uint32_t intval; + }; - bool operator==(uint32_t v) const { return v == val; } - bool operator!=(uint32_t v) const { return v != val; } + using FIXED_STRING_BASE::operator==; + using FIXED_STRING_BASE::operator!=; - std::string toString() const { return std::string(name, strnlen(name, LEN)); } + bool operator==(uint32_t v) const { return v == intval; } + bool operator!=(uint32_t v) const { return v != intval; } - void assign (const std::string& value) { std::strncpy (name, value.c_str(), LEN); } + char const* ro_data() const { return data; } + char* rw_data() { return data; } }; -typedef NAME_T<4> NAME; -typedef NAME_T<32> NAME32; -typedef NAME_T<64> NAME64; -typedef NAME_T<256> NAME256; +typedef FIXED_STRING<4> NAME; +typedef FIXED_STRING<32> NAME32; +typedef FIXED_STRING<64> NAME64; +typedef FIXED_STRING<256> NAME256; /* This struct defines a file 'context' which can be saved and later restored by an ESMReader instance. It will save the position within diff --git a/components/esm/esmreader.cpp b/components/esm/esmreader.cpp index 6ef14a70e..2a716427e 100644 --- a/components/esm/esmreader.cpp +++ b/components/esm/esmreader.cpp @@ -55,8 +55,8 @@ void ESMReader::close() mCtx.leftRec = 0; mCtx.leftSub = 0; mCtx.subCached = false; - mCtx.recName.val = 0; - mCtx.subName.val = 0; + mCtx.recName.clear(); + mCtx.subName.clear(); } void ESMReader::openRaw(Files::IStreamPtr _esm, const std::string& name) @@ -204,16 +204,18 @@ void ESMReader::getSubName() } // reading the subrecord data anyway. - getExact(mCtx.subName.name, 4); - mCtx.leftRec -= 4; + const size_t subNameSize = mCtx.subName.data_size(); + getExact(mCtx.subName.rw_data(), subNameSize); + mCtx.leftRec -= subNameSize; } bool ESMReader::isEmptyOrGetName() { if (mCtx.leftRec) { - getExact(mCtx.subName.name, 4); - mCtx.leftRec -= 4; + const size_t subNameSize = mCtx.subName.data_size(); + getExact(mCtx.subName.rw_data(), subNameSize); + mCtx.leftRec -= subNameSize; return false; } return true; @@ -267,7 +269,7 @@ NAME ESMReader::getRecName() if (!hasMoreRecs()) fail("No more records, getRecName() failed"); getName(mCtx.recName); - mCtx.leftFile -= 4; + mCtx.leftFile -= mCtx.recName.data_size(); // Make sure we don't carry over any old cached subrecord // names. This can happen in some cases when we skip parts of a diff --git a/components/esm/filter.cpp b/components/esm/filter.cpp index c3658f152..4f0519f80 100644 --- a/components/esm/filter.cpp +++ b/components/esm/filter.cpp @@ -13,7 +13,7 @@ void ESM::Filter::load (ESMReader& esm, bool &isDeleted) while (esm.hasMoreSubs()) { esm.getSubName(); - uint32_t name = esm.retSubName().val; + uint32_t name = esm.retSubName().intval; switch (name) { case ESM::SREC_NAME: diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index b9934d3d3..ba35535b8 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -16,7 +16,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index 204904502..85c24dc2d 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -19,7 +19,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index 490881fae..1bd1f9379 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index f2526554a..929c111a9 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -49,7 +49,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index 09113e8d1..3e5895c2c 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index 617040be4..d5283b8eb 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadbsgn.cpp b/components/esm/loadbsgn.cpp index 9a4d98bb7..e3b2f76a3 100644 --- a/components/esm/loadbsgn.cpp +++ b/components/esm/loadbsgn.cpp @@ -18,7 +18,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index eb9d6b8d8..3a8a11779 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -69,7 +69,7 @@ namespace ESM while (!isLoaded && esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mName = esm.getHString(); @@ -114,7 +114,7 @@ namespace ESM while (!isLoaded && esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'I','N','T','V'>::value: int waterl; diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index 61960b87d..1e18bc054 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -47,7 +47,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 2ef69e5e9..12f0d495d 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -19,7 +19,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index 739b0d7db..5ee785fb8 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -36,7 +36,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index b51782089..ddd49f8df 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -30,7 +30,7 @@ namespace ESM { while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loaddial.cpp b/components/esm/loaddial.cpp index bc87c4f57..5758dc0c4 100644 --- a/components/esm/loaddial.cpp +++ b/components/esm/loaddial.cpp @@ -28,7 +28,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'D','A','T','A'>::value: { diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index 6d8c0978c..523d8a1ef 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -16,7 +16,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index ae83c63f7..78e2fb5aa 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -18,7 +18,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 75c482d20..07611c32f 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -40,7 +40,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadinfo.cpp b/components/esm/loadinfo.cpp index 246baf026..37fd70908 100644 --- a/components/esm/loadinfo.cpp +++ b/components/esm/loadinfo.cpp @@ -35,7 +35,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'D','A','T','A'>::value: esm.getHT(mData, 12); diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index e00e73ab0..a18e321ff 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadland.cpp b/components/esm/loadland.cpp index b0b072232..87d0233b5 100644 --- a/components/esm/loadland.cpp +++ b/components/esm/loadland.cpp @@ -94,7 +94,7 @@ namespace ESM while (!isLoaded && esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'I','N','T','V'>::value: esm.getSubHeaderIs(8); @@ -125,7 +125,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'V','N','M','L'>::value: esm.skipHSub(); diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index 8c0d50324..0aed15aa9 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -15,7 +15,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index 20c700b23..2a6dac14b 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadlock.cpp b/components/esm/loadlock.cpp index fc6af8699..b14353ec5 100644 --- a/components/esm/loadlock.cpp +++ b/components/esm/loadlock.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadltex.cpp b/components/esm/loadltex.cpp index a42ae7c5b..613b706e3 100644 --- a/components/esm/loadltex.cpp +++ b/components/esm/loadltex.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadmgef.cpp b/components/esm/loadmgef.cpp index eef58aa2f..e33bd3ab4 100644 --- a/components/esm/loadmgef.cpp +++ b/components/esm/loadmgef.cpp @@ -211,7 +211,7 @@ void MagicEffect::load(ESMReader &esm, bool &isDeleted) while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'I','T','E','X'>::value: mIcon = esm.getHString(); diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index 199b4e3b2..3ba662650 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index e524e6a7c..a68c97a6a 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -26,7 +26,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadpgrd.cpp b/components/esm/loadpgrd.cpp index 69ee60eeb..15accd95b 100644 --- a/components/esm/loadpgrd.cpp +++ b/components/esm/loadpgrd.cpp @@ -46,7 +46,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mCell = esm.getHString(); diff --git a/components/esm/loadprob.cpp b/components/esm/loadprob.cpp index baf466490..6307df329 100644 --- a/components/esm/loadprob.cpp +++ b/components/esm/loadprob.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadrace.cpp b/components/esm/loadrace.cpp index a37175144..88ce08c91 100644 --- a/components/esm/loadrace.cpp +++ b/components/esm/loadrace.cpp @@ -29,7 +29,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadregn.cpp b/components/esm/loadregn.cpp index e5382f50b..6e0e6db9d 100644 --- a/components/esm/loadregn.cpp +++ b/components/esm/loadregn.cpp @@ -16,7 +16,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); @@ -61,10 +61,12 @@ namespace ESM esm.getHT(mMapColor); break; case ESM::FourCC<'S','N','A','M'>::value: + { SoundRef sr; esm.getHT(sr, 33); mSoundList.push_back(sr); break; + } case ESM::SREC_DELE: esm.skipHSub(); isDeleted = true; diff --git a/components/esm/loadrepa.cpp b/components/esm/loadrepa.cpp index e4af3d937..c04691c12 100644 --- a/components/esm/loadrepa.cpp +++ b/components/esm/loadrepa.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadscpt.cpp b/components/esm/loadscpt.cpp index b46d5b658..1adebe45f 100644 --- a/components/esm/loadscpt.cpp +++ b/components/esm/loadscpt.cpp @@ -67,15 +67,17 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'S','C','H','D'>::value: + { SCHD data; esm.getHT(data, 52); mData = data.mData; mId = data.mName.toString(); hasHeader = true; break; + } case ESM::FourCC<'S','C','V','R'>::value: // list of local variables loadSCVR(esm); @@ -113,7 +115,7 @@ namespace ESM memset(&data, 0, sizeof(data)); data.mData = mData; - memcpy(data.mName.name, mId.c_str(), mId.size()); + data.mName.assign(mId); esm.writeHNT("SCHD", data, 52); diff --git a/components/esm/loadskil.cpp b/components/esm/loadskil.cpp index c52089791..36204c940 100644 --- a/components/esm/loadskil.cpp +++ b/components/esm/loadskil.cpp @@ -138,7 +138,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::FourCC<'I','N','D','X'>::value: esm.getHT(mIndex); diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index d84fe624d..9bd806641 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index 82f169e54..3b3dc1eac 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index 728b7bc2a..947e6c9ec 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -19,7 +19,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadsscr.cpp b/components/esm/loadsscr.cpp index ab4c09750..f8854493b 100644 --- a/components/esm/loadsscr.cpp +++ b/components/esm/loadsscr.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index 62d495ee3..6c9de22bd 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -16,7 +16,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/loadtes3.cpp b/components/esm/loadtes3.cpp index 60d411fc6..b16145467 100644 --- a/components/esm/loadtes3.cpp +++ b/components/esm/loadtes3.cpp @@ -9,8 +9,8 @@ void ESM::Header::blank() { mData.version = ESM::VER_13; mData.type = 0; - mData.author.assign (""); - mData.desc.assign (""); + mData.author.clear(); + mData.desc.clear(); mData.records = 0; mFormat = CurrentFormat; mMaster.clear(); @@ -32,8 +32,8 @@ void ESM::Header::load (ESMReader &esm) esm.getSubHeader(); esm.getT(mData.version); esm.getT(mData.type); - mData.author.assign(esm.getString(sizeof(mData.author.name))); - mData.desc.assign(esm.getString(sizeof(mData.desc.name))); + mData.author.assign( esm.getString(mData.author.data_size()) ); + mData.desc.assign( esm.getString(mData.desc.data_size()) ); esm.getT(mData.records); } @@ -73,8 +73,8 @@ void ESM::Header::save (ESMWriter &esm) esm.startSubRecord("HEDR"); esm.writeT(mData.version); esm.writeT(mData.type); - esm.writeFixedSizeString(mData.author.toString(), 32); - esm.writeFixedSizeString(mData.desc.toString(), 256); + esm.writeFixedSizeString(mData.author.toString(), mData.author.data_size()); + esm.writeFixedSizeString(mData.desc.toString(), mData.desc.data_size()); esm.writeT(mData.records); esm.endRecord("HEDR"); diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 880a26bcb..4a77ff6a0 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -17,7 +17,7 @@ namespace ESM while (esm.hasMoreSubs()) { esm.getSubName(); - switch (esm.retSubName().val) + switch (esm.retSubName().intval) { case ESM::SREC_NAME: mId = esm.getHString(); diff --git a/components/esm/transport.cpp b/components/esm/transport.cpp index da0a5f767..063c03329 100644 --- a/components/esm/transport.cpp +++ b/components/esm/transport.cpp @@ -8,13 +8,13 @@ namespace ESM void Transport::add(ESMReader &esm) { - if (esm.retSubName().val == ESM::FourCC<'D','O','D','T'>::value) + if (esm.retSubName().intval == ESM::FourCC<'D','O','D','T'>::value) { Dest dodt; esm.getHExact(&dodt.mPos, 24); mList.push_back(dodt); } - else if (esm.retSubName().val == ESM::FourCC<'D','N','A','M'>::value) + else if (esm.retSubName().intval == ESM::FourCC<'D','N','A','M'>::value) { mList.back().mCellName = esm.getHString(); }