From 926c825d0c7f0a373fb6bd22d88d0df850407f3c Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Tue, 7 Jul 2015 15:37:42 +0300 Subject: [PATCH] Add NAME and DELE handling to ESM records. Changed records are those where DELE is located after NAME sub-record. And DELE is the last sub-record. --- components/esm/loadacti.cpp | 15 +++++++++++++++ components/esm/loadacti.hpp | 2 ++ components/esm/loadalch.cpp | 16 ++++++++++++++++ components/esm/loadalch.hpp | 2 ++ components/esm/loadappa.cpp | 15 +++++++++++++++ components/esm/loadappa.hpp | 2 ++ components/esm/loadarmo.cpp | 16 ++++++++++++++++ components/esm/loadarmo.hpp | 2 ++ components/esm/loadbody.cpp | 16 ++++++++++++++++ components/esm/loadbody.hpp | 2 ++ components/esm/loadbook.cpp | 15 +++++++++++++++ components/esm/loadbook.hpp | 2 ++ components/esm/loadclas.cpp | 16 ++++++++++++++++ components/esm/loadclas.hpp | 2 ++ components/esm/loadclot.cpp | 16 ++++++++++++++++ components/esm/loadclot.hpp | 2 ++ components/esm/loadcont.cpp | 16 ++++++++++++++++ components/esm/loadcont.hpp | 2 ++ components/esm/loadcrea.cpp | 15 +++++++++++++++ components/esm/loadcrea.hpp | 3 ++- components/esm/loaddoor.cpp | 15 +++++++++++++++ components/esm/loaddoor.hpp | 2 ++ components/esm/loadench.cpp | 17 +++++++++++++++++ components/esm/loadench.hpp | 2 ++ components/esm/loadfact.cpp | 16 ++++++++++++++++ components/esm/loadfact.hpp | 2 ++ components/esm/loadingr.cpp | 16 ++++++++++++++++ components/esm/loadingr.hpp | 2 ++ components/esm/loadlevlist.cpp | 15 +++++++++++++++ components/esm/loadlevlist.hpp | 2 ++ components/esm/loadligh.cpp | 15 +++++++++++++++ components/esm/loadligh.hpp | 2 ++ components/esm/loadlock.cpp | 15 +++++++++++++++ components/esm/loadlock.hpp | 2 ++ components/esm/loadmisc.cpp | 15 +++++++++++++++ components/esm/loadmisc.hpp | 2 ++ components/esm/loadnpc.cpp | 15 +++++++++++++++ components/esm/loadnpc.hpp | 2 ++ components/esm/loadprob.cpp | 15 +++++++++++++++ components/esm/loadprob.hpp | 2 ++ components/esm/loadrepa.cpp | 15 +++++++++++++++ components/esm/loadrepa.hpp | 2 ++ components/esm/loadsndg.cpp | 15 +++++++++++++++ components/esm/loadsndg.hpp | 2 ++ components/esm/loadsoun.cpp | 16 ++++++++++++++++ components/esm/loadsoun.hpp | 2 ++ components/esm/loadspel.cpp | 17 +++++++++++++++++ components/esm/loadspel.hpp | 2 ++ components/esm/loadstat.cpp | 15 +++++++++++++++ components/esm/loadstat.hpp | 2 ++ components/esm/loadweap.cpp | 16 ++++++++++++++++ components/esm/loadweap.hpp | 2 ++ components/esm/util.cpp | 20 ++++++++++++++++++++ components/esm/util.hpp | 9 +++++++++ 54 files changed, 485 insertions(+), 1 deletion(-) create mode 100644 components/esm/util.cpp diff --git a/components/esm/loadacti.cpp b/components/esm/loadacti.cpp index b5adce550..295d35f7e 100644 --- a/components/esm/loadacti.cpp +++ b/components/esm/loadacti.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Activator::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + while (esm.hasMoreSubs()) { esm.getSubName(); @@ -32,6 +39,13 @@ namespace ESM } void Activator::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("SCRI", mScript); @@ -42,5 +56,6 @@ namespace ESM mName.clear(); mScript.clear(); mModel.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadacti.hpp b/components/esm/loadacti.hpp index d9a55023b..406512a22 100644 --- a/components/esm/loadacti.hpp +++ b/components/esm/loadacti.hpp @@ -17,6 +17,8 @@ struct Activator std::string mId, mName, mScript, mModel; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadalch.cpp b/components/esm/loadalch.cpp index 18db512c0..12078a5f7 100644 --- a/components/esm/loadalch.cpp +++ b/components/esm/loadalch.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Potion::load(ESMReader &esm) { mEffects.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -46,6 +54,13 @@ namespace ESM } void Potion::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("TEXT", mIcon); esm.writeHNOCString("SCRI", mScript); @@ -64,5 +79,6 @@ namespace ESM mIcon.clear(); mScript.clear(); mEffects.mList.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadalch.hpp b/components/esm/loadalch.hpp index b90a7c448..3d1e6dee7 100644 --- a/components/esm/loadalch.hpp +++ b/components/esm/loadalch.hpp @@ -33,6 +33,8 @@ struct Potion std::string mId, mName, mModel, mIcon, mScript; EffectList mEffects; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadappa.cpp b/components/esm/loadappa.cpp index f2c82aacf..9107e5a8e 100644 --- a/components/esm/loadappa.cpp +++ b/components/esm/loadappa.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Apparatus::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ void Apparatus::load(ESMReader &esm) void Apparatus::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNCString("FNAM", mName); esm.writeHNT("AADT", mData, 16); @@ -60,5 +74,6 @@ void Apparatus::save(ESMWriter &esm) const mIcon.clear(); mScript.clear(); mName.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadappa.hpp b/components/esm/loadappa.hpp index f18b04648..62d8561a1 100644 --- a/components/esm/loadappa.hpp +++ b/components/esm/loadappa.hpp @@ -38,6 +38,8 @@ struct Apparatus AADTstruct mData; std::string mId, mModel, mIcon, mScript, mName; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadarmo.cpp b/components/esm/loadarmo.cpp index 066551d6f..626893d00 100644 --- a/components/esm/loadarmo.cpp +++ b/components/esm/loadarmo.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -41,6 +42,13 @@ namespace ESM void Armor::load(ESMReader &esm) { mParts.mParts.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -80,6 +88,13 @@ namespace ESM void Armor::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("SCRI", mScript); @@ -103,5 +118,6 @@ namespace ESM mIcon.clear(); mScript.clear(); mEnchant.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadarmo.hpp b/components/esm/loadarmo.hpp index 54416fd31..eb911254f 100644 --- a/components/esm/loadarmo.hpp +++ b/components/esm/loadarmo.hpp @@ -96,6 +96,8 @@ struct Armor std::string mId, mName, mModel, mIcon, mScript, mEnchant; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadbody.cpp b/components/esm/loadbody.cpp index ed24ded57..644eb3b50 100644 --- a/components/esm/loadbody.cpp +++ b/components/esm/loadbody.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,12 @@ namespace ESM void BodyPart::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -38,6 +45,13 @@ void BodyPart::load(ESMReader &esm) } void BodyPart::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mRace); esm.writeHNT("BYDT", mData, 4); @@ -52,5 +66,7 @@ void BodyPart::save(ESMWriter &esm) const mModel.clear(); mRace.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadbody.hpp b/components/esm/loadbody.hpp index c48c31305..8e1e81f82 100644 --- a/components/esm/loadbody.hpp +++ b/components/esm/loadbody.hpp @@ -60,6 +60,8 @@ struct BodyPart BYDTstruct mData; std::string mId, mModel, mRace; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadbook.cpp b/components/esm/loadbook.cpp index 47f52fc31..aec361873 100644 --- a/components/esm/loadbook.cpp +++ b/components/esm/loadbook.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Book::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -48,6 +55,13 @@ namespace ESM } void Book::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("BKDT", mData, 20); @@ -70,5 +84,6 @@ namespace ESM mScript.clear(); mEnchant.clear(); mText.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadbook.hpp b/components/esm/loadbook.hpp index 6211b3e45..2f374c4b2 100644 --- a/components/esm/loadbook.hpp +++ b/components/esm/loadbook.hpp @@ -28,6 +28,8 @@ struct Book std::string mName, mModel, mIcon, mScript, mEnchant, mText; std::string mId; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadclas.cpp b/components/esm/loadclas.cpp index 66acaea72..df47a1a33 100644 --- a/components/esm/loadclas.cpp +++ b/components/esm/loadclas.cpp @@ -5,6 +5,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -41,6 +42,12 @@ namespace ESM void Class::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -69,6 +76,13 @@ namespace ESM } void Class::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mName); esm.writeHNT("CLDT", mData, 60); esm.writeHNOString("DESC", mDescription); @@ -87,5 +101,7 @@ namespace ESM for (int i=0; i<5; ++i) for (int i2=0; i2<2; ++i2) mData.mSkills[i][i2] = 0; + + mIsDeleted = false; } } diff --git a/components/esm/loadclas.hpp b/components/esm/loadclas.hpp index 972b48e88..b61913734 100644 --- a/components/esm/loadclas.hpp +++ b/components/esm/loadclas.hpp @@ -73,6 +73,8 @@ struct Class std::string mId, mName, mDescription; CLDTstruct mData; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadclot.cpp b/components/esm/loadclot.cpp index 5f49b5e70..1c73c4f21 100644 --- a/components/esm/loadclot.cpp +++ b/components/esm/loadclot.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Clothing::load(ESMReader &esm) { mParts.mParts.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -50,6 +58,13 @@ namespace ESM void Clothing::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("CTDT", mData, 12); @@ -74,5 +89,6 @@ namespace ESM mIcon.clear(); mEnchant.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadclot.hpp b/components/esm/loadclot.hpp index 6945f224a..8b4a8b3bb 100644 --- a/components/esm/loadclot.hpp +++ b/components/esm/loadclot.hpp @@ -48,6 +48,8 @@ struct Clothing std::string mId, mName, mModel, mIcon, mEnchant, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadcont.cpp b/components/esm/loadcont.cpp index 3481189c3..f54fe66e2 100644 --- a/components/esm/loadcont.cpp +++ b/components/esm/loadcont.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -27,6 +28,13 @@ namespace ESM void Container::load(ESMReader &esm) { mInventory.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasWeight = false; bool hasFlags = false; while (esm.hasMoreSubs()) @@ -71,6 +79,13 @@ namespace ESM void Container::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("CNDT", mWeight, 4); @@ -89,5 +104,6 @@ namespace ESM mWeight = 0; mFlags = 0x8; // set default flag value mInventory.mList.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadcont.hpp b/components/esm/loadcont.hpp index ab587f935..51166b8d4 100644 --- a/components/esm/loadcont.hpp +++ b/components/esm/loadcont.hpp @@ -52,6 +52,8 @@ struct Container int mFlags; InventoryList mInventory; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 50c47349c..6da32eed7 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -17,6 +18,12 @@ namespace ESM { mSpells.mList.clear(); mTransport.mList.clear(); + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + mScale = 1.f; mHasAI = false; bool hasNpdt = false; @@ -84,6 +91,13 @@ namespace ESM { void Creature::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("CNAM", mOriginal); esm.writeHNOCString("FNAM", mName); @@ -127,6 +141,7 @@ namespace ESM { mAiData.mServices = 0; mAiPackage.mList.clear(); mTransport.mList.clear(); + mIsDeleted = false; } const std::vector& Creature::getTransport() const diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 47e5954a5..fb43f6272 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -91,12 +91,13 @@ struct Creature InventoryList mInventory; SpellList mSpells; - bool mHasAI; AIData mAiData; AIPackageList mAiPackage; Transport mTransport; + bool mIsDeleted; + const std::vector& getTransport() const; void load(ESMReader &esm); diff --git a/components/esm/loaddoor.cpp b/components/esm/loaddoor.cpp index f446eed61..6ee43fd1a 100644 --- a/components/esm/loaddoor.cpp +++ b/components/esm/loaddoor.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Door::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + while (esm.hasMoreSubs()) { esm.getSubName(); @@ -39,6 +46,13 @@ namespace ESM void Door::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("SCRI", mScript); @@ -53,5 +67,6 @@ namespace ESM mScript.clear(); mOpenSound.clear(); mCloseSound.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loaddoor.hpp b/components/esm/loaddoor.hpp index 3073f4e9d..b0326a744 100644 --- a/components/esm/loaddoor.hpp +++ b/components/esm/loaddoor.hpp @@ -17,6 +17,8 @@ struct Door std::string mId, mName, mModel, mScript, mOpenSound, mCloseSound; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadench.cpp b/components/esm/loadench.cpp index 54690d9a0..88d9e0f2e 100644 --- a/components/esm/loadench.cpp +++ b/components/esm/loadench.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Enchantment::load(ESMReader &esm) { mEffects.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -36,6 +44,13 @@ void Enchantment::load(ESMReader &esm) void Enchantment::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNT("ENDT", mData, 16); mEffects.save(esm); } @@ -48,5 +63,7 @@ void Enchantment::save(ESMWriter &esm) const mData.mAutocalc = 0; mEffects.mList.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadench.hpp b/components/esm/loadench.hpp index cfcdd4edc..c9b19e31b 100644 --- a/components/esm/loadench.hpp +++ b/components/esm/loadench.hpp @@ -42,6 +42,8 @@ struct Enchantment ENDTstruct mData; EffectList mEffects; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadfact.cpp b/components/esm/loadfact.cpp index 006ca0ce0..9149c2a30 100644 --- a/components/esm/loadfact.cpp +++ b/components/esm/loadfact.cpp @@ -5,6 +5,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -32,6 +33,12 @@ void Faction::load(ESMReader &esm) for (int i=0;i<10;++i) mRanks[i].clear(); + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + int rankCounter=0; bool hasData = false; while (esm.hasMoreSubs()) @@ -71,6 +78,13 @@ void Faction::load(ESMReader &esm) } void Faction::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mName); for (int i = 0; i < 10; i++) @@ -109,5 +123,7 @@ void Faction::save(ESMWriter &esm) const mData.mSkills[i] = 0; mReactions.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadfact.hpp b/components/esm/loadfact.hpp index 8645e23fd..fec13b1ca 100644 --- a/components/esm/loadfact.hpp +++ b/components/esm/loadfact.hpp @@ -62,6 +62,8 @@ struct Faction // Name of faction ranks (may be empty for NPC factions) std::string mRanks[10]; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadingr.cpp b/components/esm/loadingr.cpp index 7e0cc3168..8bf0278f7 100644 --- a/components/esm/loadingr.cpp +++ b/components/esm/loadingr.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Ingredient::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -67,6 +74,13 @@ namespace ESM void Ingredient::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("IRDT", mData, 56); @@ -89,5 +103,7 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadingr.hpp b/components/esm/loadingr.hpp index 5846a9780..69a650180 100644 --- a/components/esm/loadingr.hpp +++ b/components/esm/loadingr.hpp @@ -31,6 +31,8 @@ struct Ingredient IRDTstruct mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadlevlist.cpp b/components/esm/loadlevlist.cpp index ca5c5d74d..c8cb110a6 100644 --- a/components/esm/loadlevlist.cpp +++ b/components/esm/loadlevlist.cpp @@ -3,12 +3,19 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { void LevelledListBase::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + esm.getHNT(mFlags, "DATA"); esm.getHNT(mChanceNone, "NNAM"); @@ -42,6 +49,13 @@ namespace ESM } void LevelledListBase::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNT("DATA", mFlags); esm.writeHNT("NNAM", mChanceNone); esm.writeHNT("INDX", mList.size()); @@ -58,6 +72,7 @@ namespace ESM mFlags = 0; mChanceNone = 0; mList.clear(); + mIsDeleted = false; } unsigned int CreatureLevList::sRecordId = REC_LEVC; diff --git a/components/esm/loadlevlist.hpp b/components/esm/loadlevlist.hpp index dc6fcda5e..4165275b2 100644 --- a/components/esm/loadlevlist.hpp +++ b/components/esm/loadlevlist.hpp @@ -36,6 +36,8 @@ struct LevelledListBase std::vector mList; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadligh.cpp b/components/esm/loadligh.cpp index 26d70d964..bd91e096c 100644 --- a/components/esm/loadligh.cpp +++ b/components/esm/loadligh.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Light::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -45,6 +52,13 @@ namespace ESM } void Light::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("ITEX", mIcon); @@ -66,5 +80,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mName.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadligh.hpp b/components/esm/loadligh.hpp index ed8c36665..76274e6f4 100644 --- a/components/esm/loadligh.hpp +++ b/components/esm/loadligh.hpp @@ -47,6 +47,8 @@ struct Light std::string mSound, mScript, mModel, mIcon, mName, mId; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadlock.cpp b/components/esm/loadlock.cpp index 2747a6f78..c1e866b58 100644 --- a/components/esm/loadlock.cpp +++ b/components/esm/loadlock.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Lockpick::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = true; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ namespace ESM void Lockpick::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); @@ -61,5 +75,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadlock.hpp b/components/esm/loadlock.hpp index 0d678cd64..af18773ed 100644 --- a/components/esm/loadlock.hpp +++ b/components/esm/loadlock.hpp @@ -27,6 +27,8 @@ struct Lockpick Data mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadmisc.cpp b/components/esm/loadmisc.cpp index 81c094f2b..11d2f2a05 100644 --- a/components/esm/loadmisc.cpp +++ b/components/esm/loadmisc.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Miscellaneous::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -41,6 +48,13 @@ namespace ESM void Miscellaneous::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("MCDT", mData, 12); @@ -57,5 +71,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadmisc.hpp b/components/esm/loadmisc.hpp index 6e0b4e01b..5d5e9f66f 100644 --- a/components/esm/loadmisc.hpp +++ b/components/esm/loadmisc.hpp @@ -32,6 +32,8 @@ struct Miscellaneous std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadnpc.cpp b/components/esm/loadnpc.cpp index 44d298785..280db0791 100644 --- a/components/esm/loadnpc.cpp +++ b/components/esm/loadnpc.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -17,6 +18,12 @@ namespace ESM mTransport.mList.clear(); mAiPackage.mList.clear(); + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasNpdt = false; bool hasFlags = false; mHasAI = false; @@ -103,6 +110,13 @@ namespace ESM } void NPC::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNCString("RNAM", mRace); @@ -178,6 +192,7 @@ namespace ESM mScript.clear(); mHair.clear(); mHead.clear(); + mIsDeleted = false; } int NPC::getFactionRank() const diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 9bda9560e..7b75cb178 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -130,6 +130,8 @@ struct NPC // body parts std::string mHair, mHead; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadprob.cpp b/components/esm/loadprob.cpp index c5f80c584..12f7ad00a 100644 --- a/components/esm/loadprob.cpp +++ b/components/esm/loadprob.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Probe::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = true; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ namespace ESM void Probe::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); @@ -61,5 +75,6 @@ namespace ESM mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadprob.hpp b/components/esm/loadprob.hpp index c737757aa..9daab6b1b 100644 --- a/components/esm/loadprob.hpp +++ b/components/esm/loadprob.hpp @@ -27,6 +27,8 @@ struct Probe Data mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadrepa.cpp b/components/esm/loadrepa.cpp index f90f9e39d..608536f02 100644 --- a/components/esm/loadrepa.cpp +++ b/components/esm/loadrepa.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Repair::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = true; while (esm.hasMoreSubs()) { @@ -43,6 +50,13 @@ void Repair::load(ESMReader &esm) void Repair::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); @@ -61,5 +75,6 @@ void Repair::save(ESMWriter &esm) const mModel.clear(); mIcon.clear(); mScript.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadrepa.hpp b/components/esm/loadrepa.hpp index e765bc93a..a660574be 100644 --- a/components/esm/loadrepa.hpp +++ b/components/esm/loadrepa.hpp @@ -27,6 +27,8 @@ struct Repair Data mData; std::string mId, mName, mModel, mIcon, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadsndg.cpp b/components/esm/loadsndg.cpp index 5ee6f5245..f92c4eee8 100644 --- a/components/esm/loadsndg.cpp +++ b/components/esm/loadsndg.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void SoundGenerator::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -36,6 +43,13 @@ namespace ESM } void SoundGenerator::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNT("DATA", mType, 4); esm.writeHNOCString("CNAM", mCreature); esm.writeHNOCString("SNAM", mSound); @@ -46,5 +60,6 @@ namespace ESM mType = LeftFoot; mCreature.clear(); mSound.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadsndg.hpp b/components/esm/loadsndg.hpp index 056958f0a..e486976f5 100644 --- a/components/esm/loadsndg.hpp +++ b/components/esm/loadsndg.hpp @@ -36,6 +36,8 @@ struct SoundGenerator std::string mId, mCreature, mSound; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadsoun.cpp b/components/esm/loadsoun.cpp index 690c1b448..19e8a5d80 100644 --- a/components/esm/loadsoun.cpp +++ b/components/esm/loadsoun.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Sound::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -34,6 +41,13 @@ namespace ESM void Sound::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mSound); esm.writeHNT("DATA", mData, 3); } @@ -45,5 +59,7 @@ namespace ESM mData.mVolume = 128; mData.mMinRange = 0; mData.mMaxRange = 255; + + mIsDeleted = false; } } diff --git a/components/esm/loadsoun.hpp b/components/esm/loadsoun.hpp index ff2202ca7..95c89b29d 100644 --- a/components/esm/loadsoun.hpp +++ b/components/esm/loadsoun.hpp @@ -23,6 +23,8 @@ struct Sound SOUNstruct mData; std::string mId, mSound; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadspel.cpp b/components/esm/loadspel.cpp index 96c048e0a..cac06b200 100644 --- a/components/esm/loadspel.cpp +++ b/components/esm/loadspel.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -11,6 +12,13 @@ namespace ESM void Spell::load(ESMReader &esm) { mEffects.mList.clear(); + + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -39,6 +47,13 @@ namespace ESM void Spell::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNOCString("FNAM", mName); esm.writeHNT("SPDT", mData, 12); mEffects.save(esm); @@ -53,5 +68,7 @@ namespace ESM mName.clear(); mEffects.mList.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadspel.hpp b/components/esm/loadspel.hpp index 491da1d17..2aba131ad 100644 --- a/components/esm/loadspel.hpp +++ b/components/esm/loadspel.hpp @@ -45,6 +45,8 @@ struct Spell std::string mId, mName; EffectList mEffects; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadstat.cpp b/components/esm/loadstat.cpp index b0ab89bed..a49caba89 100644 --- a/components/esm/loadstat.cpp +++ b/components/esm/loadstat.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,15 +11,29 @@ namespace ESM void Static::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + mModel = esm.getHNString("MODL"); } void Static::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); } void Static::blank() { mModel.clear(); + mIsDeleted = false; } } diff --git a/components/esm/loadstat.hpp b/components/esm/loadstat.hpp index aa4fe67b8..c4306ad8f 100644 --- a/components/esm/loadstat.hpp +++ b/components/esm/loadstat.hpp @@ -28,6 +28,8 @@ struct Static std::string mId, mModel; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/loadweap.cpp b/components/esm/loadweap.cpp index 981a5815a..66d65d0f5 100644 --- a/components/esm/loadweap.cpp +++ b/components/esm/loadweap.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include "defs.hpp" +#include "util.hpp" namespace ESM { @@ -10,6 +11,12 @@ namespace ESM void Weapon::load(ESMReader &esm) { + mId = esm.getHNString("NAME"); + if (mIsDeleted = readDeleSubRecord(esm)) + { + return; + } + bool hasData = false; while (esm.hasMoreSubs()) { @@ -45,6 +52,13 @@ namespace ESM } void Weapon::save(ESMWriter &esm) const { + esm.writeHNCString("NAME", mId); + if (mIsDeleted) + { + writeDeleSubRecord(esm); + return; + } + esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNT("WPDT", mData, 32); @@ -72,5 +86,7 @@ namespace ESM mIcon.clear(); mEnchant.clear(); mScript.clear(); + + mIsDeleted = false; } } diff --git a/components/esm/loadweap.hpp b/components/esm/loadweap.hpp index f66e9f3a6..30dfbc92a 100644 --- a/components/esm/loadweap.hpp +++ b/components/esm/loadweap.hpp @@ -69,6 +69,8 @@ struct Weapon std::string mId, mName, mModel, mIcon, mEnchant, mScript; + bool mIsDeleted; + void load(ESMReader &esm); void save(ESMWriter &esm) const; diff --git a/components/esm/util.cpp b/components/esm/util.cpp new file mode 100644 index 000000000..c20bd4d51 --- /dev/null +++ b/components/esm/util.cpp @@ -0,0 +1,20 @@ +#include "util.hpp" + +namespace ESM +{ + bool readDeleSubRecord(ESMReader &esm) + { + if (esm.isNextSub("DELE")) + { + esm.getSubName(); + esm.skipHSub(); + return true; + } + return false; + } + + void writeDeleSubRecord(ESMWriter &esm) + { + esm.writeHNString("DELE", ""); + } +} diff --git a/components/esm/util.hpp b/components/esm/util.hpp index a80df2456..c670fb23a 100644 --- a/components/esm/util.hpp +++ b/components/esm/util.hpp @@ -1,9 +1,15 @@ #ifndef OPENMW_ESM_UTIL_H #define OPENMW_ESM_UTIL_H +#include + #include #include +#include "esmreader.hpp" +#include "esmwriter.hpp" +#include "loadbsgn.hpp" + namespace ESM { @@ -48,6 +54,9 @@ struct Vector3 } }; +bool readDeleSubRecord(ESMReader &esm); +void writeDeleSubRecord(ESMWriter &esm); + } #endif