ESSImport: read script variables (not converted yet)

openmw-35
scrawl 10 years ago
parent 98402e579d
commit e203127952

@ -14,6 +14,8 @@ set(ESSIMPORTER_FILES
importdial.cpp importdial.cpp
importques.cpp importques.cpp
importjour.cpp importjour.cpp
importscri.cpp
importscpt.cpp
importercontext.cpp importercontext.cpp
converter.cpp converter.cpp
convertacdt.cpp convertacdt.cpp

@ -25,6 +25,7 @@
#include "importdial.hpp" #include "importdial.hpp"
#include "importques.hpp" #include "importques.hpp"
#include "importjour.hpp" #include "importjour.hpp"
#include "importscpt.hpp"
#include "convertacdt.hpp" #include "convertacdt.hpp"
#include "convertnpcc.hpp" #include "convertnpcc.hpp"
@ -437,6 +438,17 @@ public:
} }
}; };
/// Running global script
class ConvertSCPT : public Converter
{
public:
virtual void read(ESM::ESMReader &esm)
{
SCPT script;
script.load(esm);
}
};
} }
#endif #endif

@ -81,18 +81,7 @@ namespace ESSImport
if (esm.isNextSub("CRED")) // creature only if (esm.isNextSub("CRED")) // creature only
esm.getHExact(mCombatStats, 3*2*sizeof(int)); esm.getHExact(mCombatStats, 3*2*sizeof(int));
mScript = esm.getHNOString("SCRI"); mSCRI.load(esm);
// script variables?
if (!mScript.empty())
{
if (esm.isNextSub("SLCS"))
esm.skipHSub();
if (esm.isNextSub("SLSD")) // Short Data?
esm.skipHSub();
if (esm.isNextSub("SLFD")) // Float Data?
esm.skipHSub();
}
if (esm.isNextSub("ND3D")) if (esm.isNextSub("ND3D"))
esm.skipHSub(); esm.skipHSub();

@ -5,6 +5,8 @@
#include <components/esm/cellref.hpp> #include <components/esm/cellref.hpp>
#include "importscri.hpp"
namespace ESM namespace ESM
{ {
struct ESMReader; struct ESMReader;
@ -50,7 +52,7 @@ namespace ESSImport
// to change them ingame // to change them ingame
int mCombatStats[3][2]; int mCombatStats[3][2];
std::string mScript; SCRI mSCRI;
void load(ESM::ESMReader& esm); void load(ESM::ESMReader& esm);
}; };

@ -234,6 +234,7 @@ namespace ESSImport
converters[ESM::REC_DIAL] = boost::shared_ptr<Converter>(new ConvertDIAL()); converters[ESM::REC_DIAL] = boost::shared_ptr<Converter>(new ConvertDIAL());
converters[ESM::REC_QUES] = boost::shared_ptr<Converter>(new ConvertQUES()); converters[ESM::REC_QUES] = boost::shared_ptr<Converter>(new ConvertQUES());
converters[recJOUR ] = boost::shared_ptr<Converter>(new ConvertJOUR()); converters[recJOUR ] = boost::shared_ptr<Converter>(new ConvertJOUR());
converters[ESM::REC_SCPT] = boost::shared_ptr<Converter>(new ConvertSCPT());
std::set<unsigned int> unknownRecords; std::set<unsigned int> unknownRecords;

@ -29,18 +29,7 @@ namespace ESSImport
if (esm.isNextSub("XIDX")) // index in the stack? if (esm.isNextSub("XIDX")) // index in the stack?
esm.skipHSub(); esm.skipHSub();
std::string script = esm.getHNOString("SCRI"); item.mSCRI.load(esm);
// script variables?
// unsure if before or after ESM::CellRef
if (!script.empty())
{
if (esm.isNextSub("SLCS"))
esm.skipHSub();
if (esm.isNextSub("SLSD")) // Short Data?
esm.skipHSub();
if (esm.isNextSub("SLFD")) // Float Data?
esm.skipHSub();
}
// for XSOL and XCHG seen so far, but probably others too // for XSOL and XCHG seen so far, but probably others too
item.ESM::CellRef::loadData(esm); item.ESM::CellRef::loadData(esm);

@ -5,6 +5,7 @@
#include <string> #include <string>
#include <components/esm/cellref.hpp> #include <components/esm/cellref.hpp>
#include "importscri.hpp"
namespace ESM namespace ESM
{ {
@ -21,6 +22,7 @@ namespace ESSImport
std::string mId; std::string mId;
int mCount; int mCount;
int mRelativeEquipmentSlot; int mRelativeEquipmentSlot;
SCRI mSCRI;
}; };
std::vector<InventoryItem> mItems; std::vector<InventoryItem> mItems;

@ -0,0 +1,20 @@
#include "importscpt.hpp"
#include <components/esm/esmreader.hpp>
namespace ESSImport
{
void SCPT::load(ESM::ESMReader &esm)
{
esm.getHNT(mSCHD, "SCHD");
mSCRI.load(esm);
mRNAM = -1;
esm.getHNOT(mRNAM, "RNAM");
}
}

@ -0,0 +1,32 @@
#ifndef OPENMW_ESSIMPORT_IMPORTSCPT_H
#define OPENMW_ESSIMPORT_IMPORTSCPT_H
#include "importscri.hpp"
#include <components/esm/loadscpt.hpp>
namespace ESM
{
class ESMReader;
}
namespace ESSImport
{
// A running global script
// TODO: test how targeted scripts are saved
struct SCPT
{
ESM::Script::SCHD mSCHD;
// values of local variables
SCRI mSCRI;
int mRNAM; // unknown, seems to be -1 for some scripts, some huge integer for others
void load(ESM::ESMReader& esm);
};
}
#endif

@ -0,0 +1,55 @@
#include "importscri.hpp"
#include <components/esm/esmreader.hpp>
namespace ESSImport
{
void SCRI::load(ESM::ESMReader &esm)
{
mScript = esm.getHNOString("SCRI");
int numShorts = 0, numLongs = 0, numFloats = 0;
if (esm.isNextSub("SLCS"))
{
esm.getSubHeader();
esm.getT(numShorts);
esm.getT(numLongs);
esm.getT(numFloats);
}
if (esm.isNextSub("SLSD"))
{
esm.getSubHeader();
for (int i=0; i<numShorts; ++i)
{
short val;
esm.getT(val);
mShorts.push_back(val);
}
}
// I haven't seen Longs in a save file yet, but SLLD would make sense for the name
// TODO: test this
if (esm.isNextSub("SLLD"))
{
esm.getSubHeader();
for (int i=0; i<numLongs; ++i)
{
int val;
esm.getT(val);
mLongs.push_back(val);
}
}
if (esm.isNextSub("SLFD"))
{
esm.getSubHeader();
for (int i=0; i<numFloats; ++i)
{
float val;
esm.getT(val);
mFloats.push_back(val);
}
}
}
}

@ -0,0 +1,30 @@
#ifndef OPENMW_ESSIMPORT_IMPORTSCRI_H
#define OPENMW_ESSIMPORT_IMPORTSCRI_H
#include <components/esm/variant.hpp>
#include <vector>
namespace ESM
{
class ESMReader;
}
namespace ESSImport
{
/// Local variable assigments for a running script
struct SCRI
{
std::string mScript;
std::vector<short> mShorts;
std::vector<int> mLongs;
std::vector<float> mFloats;
void load(ESM::ESMReader& esm);
};
}
#endif

@ -7,12 +7,6 @@
namespace ESM namespace ESM
{ {
struct SCHD
{
NAME32 mName;
Script::SCHDstruct mData;
};
unsigned int Script::sRecordId = REC_SCPT; unsigned int Script::sRecordId = REC_SCPT;
void Script::load(ESMReader &esm) void Script::load(ESMReader &esm)
@ -92,32 +86,6 @@ void Script::load(ESMReader &esm)
if (esm.isNextSub("SCVR")) { if (esm.isNextSub("SCVR")) {
esm.skipHSub(); esm.skipHSub();
} }
// ESS only, TODO: move
if (esm.isNextSub("SLCS"))
{
esm.getSubHeader();
char unknown[12];
esm.getExact(unknown, 12);
}
if (esm.isNextSub("SLSD"))
{
float read;
esm.getSubHeader();
// values of variables?
for (int i=0; i<mData.mNumShorts; ++i)
esm.getExact(&read, 2);
for (int i=0; i<mData.mNumLongs; ++i)
esm.getExact(&read, 4);
for (int i=0; i<mData.mNumFloats; ++i)
esm.getExact(&read, 4);
}
if (esm.isNextSub("RNAM"))
{
// RefNum? something to do with targetted scripts?
int refnum;
esm.getHT(refnum);
}
} }
void Script::save(ESMWriter &esm) const void Script::save(ESMWriter &esm) const
{ {

@ -26,6 +26,11 @@ public:
/// Data from script-precompling in the editor. /// Data from script-precompling in the editor.
/// \warning Do not use them. OpenCS currently does not precompile scripts. /// \warning Do not use them. OpenCS currently does not precompile scripts.
int mNumShorts, mNumLongs, mNumFloats, mScriptDataSize, mStringTableSize; int mNumShorts, mNumLongs, mNumFloats, mScriptDataSize, mStringTableSize;
};
struct SCHD
{
NAME32 mName;
Script::SCHDstruct mData;
}; // 52 bytes }; // 52 bytes
std::string mId; std::string mId;

Loading…
Cancel
Save