diff --git a/apps/essimporter/CMakeLists.txt b/apps/essimporter/CMakeLists.txt index 409b8bcff..76fc9aa94 100644 --- a/apps/essimporter/CMakeLists.txt +++ b/apps/essimporter/CMakeLists.txt @@ -24,6 +24,7 @@ set(ESSIMPORTER_FILES convertcrec.cpp convertcntc.cpp convertscri.cpp + convertscpt.cpp ) add_executable(openmw-essimporter diff --git a/apps/essimporter/converter.hpp b/apps/essimporter/converter.hpp index 28d904d3c..a5b2b1a66 100644 --- a/apps/essimporter/converter.hpp +++ b/apps/essimporter/converter.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "importcrec.hpp" #include "importcntc.hpp" @@ -30,6 +31,7 @@ #include "convertacdt.hpp" #include "convertnpcc.hpp" +#include "convertscpt.hpp" namespace ESSImport { @@ -529,7 +531,21 @@ public: { SCPT script; script.load(esm); + ESM::GlobalScript out; + convertSCPT(script, out); + mScripts.push_back(out); } + virtual void write(ESM::ESMWriter &esm) + { + for (std::vector::const_iterator it = mScripts.begin(); it != mScripts.end(); ++it) + { + esm.startRecord(ESM::REC_GSCR); + it->save(esm); + esm.endRecord(ESM::REC_GSCR); + } + } +private: + std::vector mScripts; }; } diff --git a/apps/essimporter/convertscpt.cpp b/apps/essimporter/convertscpt.cpp new file mode 100644 index 000000000..be1d03736 --- /dev/null +++ b/apps/essimporter/convertscpt.cpp @@ -0,0 +1,17 @@ +#include "convertscpt.hpp" + +#include + +#include "convertscri.hpp" + +namespace ESSImport +{ + + void convertSCPT(const SCPT &scpt, ESM::GlobalScript &out) + { + out.mId = Misc::StringUtils::lowerCase(scpt.mSCHD.mName.toString()); + out.mRunning = scpt.mHasRNAM; + convertSCRI(scpt.mSCRI, out.mLocals); + } + +} diff --git a/apps/essimporter/convertscpt.hpp b/apps/essimporter/convertscpt.hpp new file mode 100644 index 000000000..3390bd607 --- /dev/null +++ b/apps/essimporter/convertscpt.hpp @@ -0,0 +1,15 @@ +#ifndef OPENMW_ESSIMPORT_CONVERTSCPT_H +#define OPENMW_ESSIMPORT_CONVERTSCPT_H + +#include + +#include "importscpt.hpp" + +namespace ESSImport +{ + +void convertSCPT(const SCPT& scpt, ESM::GlobalScript& out); + +} + +#endif diff --git a/apps/essimporter/importscpt.cpp b/apps/essimporter/importscpt.cpp index 374fd05fa..8c9d00879 100644 --- a/apps/essimporter/importscpt.cpp +++ b/apps/essimporter/importscpt.cpp @@ -14,7 +14,13 @@ namespace ESSImport mSCRI.load(esm); mRNAM = -1; - esm.getHNOT(mRNAM, "RNAM"); + if (esm.isNextSub("RNAM")) + { + mHasRNAM = true; + esm.getHT(mRNAM); + } + else + mHasRNAM = false; } } diff --git a/apps/essimporter/importscpt.hpp b/apps/essimporter/importscpt.hpp index ca2439dda..955139606 100644 --- a/apps/essimporter/importscpt.hpp +++ b/apps/essimporter/importscpt.hpp @@ -22,6 +22,7 @@ namespace ESSImport // values of local variables SCRI mSCRI; + bool mHasRNAM; int mRNAM; // unknown, seems to be -1 for some scripts, some huge integer for others void load(ESM::ESMReader& esm); diff --git a/components/esm/globalscript.hpp b/components/esm/globalscript.hpp index 43c859e09..8b7e62795 100644 --- a/components/esm/globalscript.hpp +++ b/components/esm/globalscript.hpp @@ -12,7 +12,7 @@ namespace ESM struct GlobalScript { - std::string mId; + std::string mId; /// \note must be lowercase Locals mLocals; int mRunning; std::string mTargetId; // for targeted scripts