|
|
|
@ -6,7 +6,6 @@
|
|
|
|
|
#include <components/esm/locals.hpp>
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
#include <components/compiler/locals.hpp>
|
|
|
|
|
#include <components/compiler/exception.hpp>
|
|
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
#include "../mwbase/scriptmanager.hpp"
|
|
|
|
@ -65,19 +64,12 @@ namespace MWScript
|
|
|
|
|
|
|
|
|
|
bool Locals::hasVar(const std::string &script, const std::string &var)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ensure (script);
|
|
|
|
|
ensure (script);
|
|
|
|
|
|
|
|
|
|
const Compiler::Locals& locals =
|
|
|
|
|
MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
|
|
|
int index = locals.getIndex(var);
|
|
|
|
|
return (index != -1);
|
|
|
|
|
}
|
|
|
|
|
catch (const Compiler::SourceException&)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const Compiler::Locals& locals =
|
|
|
|
|
MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
|
|
|
int index = locals.getIndex(var);
|
|
|
|
|
return (index != -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Locals::getIntVar(const std::string &script, const std::string &var)
|
|
|
|
@ -162,42 +154,36 @@ namespace MWScript
|
|
|
|
|
if (!mInitialised)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
const Compiler::Locals& declarations =
|
|
|
|
|
MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<3; ++i)
|
|
|
|
|
{
|
|
|
|
|
const Compiler::Locals& declarations =
|
|
|
|
|
MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
|
|
|
char type = 0;
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<3; ++i)
|
|
|
|
|
switch (i)
|
|
|
|
|
{
|
|
|
|
|
char type = 0;
|
|
|
|
|
case 0: type = 's'; break;
|
|
|
|
|
case 1: type = 'l'; break;
|
|
|
|
|
case 2: type = 'f'; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
{
|
|
|
|
|
case 0: type = 's'; break;
|
|
|
|
|
case 1: type = 'l'; break;
|
|
|
|
|
case 2: type = 'f'; break;
|
|
|
|
|
}
|
|
|
|
|
const std::vector<std::string>& names = declarations.get (type);
|
|
|
|
|
|
|
|
|
|
const std::vector<std::string>& names = declarations.get (type);
|
|
|
|
|
for (int i2=0; i2<static_cast<int> (names.size()); ++i2)
|
|
|
|
|
{
|
|
|
|
|
ESM::Variant value;
|
|
|
|
|
|
|
|
|
|
for (int i2=0; i2<static_cast<int> (names.size()); ++i2)
|
|
|
|
|
switch (i)
|
|
|
|
|
{
|
|
|
|
|
ESM::Variant value;
|
|
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
|
{
|
|
|
|
|
case 0: value.setType (ESM::VT_Int); value.setInteger (mShorts.at (i2)); break;
|
|
|
|
|
case 1: value.setType (ESM::VT_Int); value.setInteger (mLongs.at (i2)); break;
|
|
|
|
|
case 2: value.setType (ESM::VT_Float); value.setFloat (mFloats.at (i2)); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locals.mVariables.emplace_back (names[i2], value);
|
|
|
|
|
case 0: value.setType (ESM::VT_Int); value.setInteger (mShorts.at (i2)); break;
|
|
|
|
|
case 1: value.setType (ESM::VT_Int); value.setInteger (mLongs.at (i2)); break;
|
|
|
|
|
case 2: value.setType (ESM::VT_Float); value.setFloat (mFloats.at (i2)); break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locals.mVariables.emplace_back (names[i2], value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const Compiler::SourceException&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -206,72 +192,66 @@ namespace MWScript
|
|
|
|
|
{
|
|
|
|
|
ensure (script);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const Compiler::Locals& declarations =
|
|
|
|
|
MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
|
|
|
const Compiler::Locals& declarations =
|
|
|
|
|
MWBase::Environment::get().getScriptManager()->getLocals(script);
|
|
|
|
|
|
|
|
|
|
int index = 0, numshorts = 0, numlongs = 0;
|
|
|
|
|
for (unsigned int v=0; v<locals.mVariables.size();++v)
|
|
|
|
|
{
|
|
|
|
|
ESM::VarType type = locals.mVariables[v].second.getType();
|
|
|
|
|
if (type == ESM::VT_Short)
|
|
|
|
|
++numshorts;
|
|
|
|
|
else if (type == ESM::VT_Int)
|
|
|
|
|
++numlongs;
|
|
|
|
|
}
|
|
|
|
|
int index = 0, numshorts = 0, numlongs = 0;
|
|
|
|
|
for (unsigned int v=0; v<locals.mVariables.size();++v)
|
|
|
|
|
{
|
|
|
|
|
ESM::VarType type = locals.mVariables[v].second.getType();
|
|
|
|
|
if (type == ESM::VT_Short)
|
|
|
|
|
++numshorts;
|
|
|
|
|
else if (type == ESM::VT_Int)
|
|
|
|
|
++numlongs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (std::vector<std::pair<std::string, ESM::Variant> >::const_iterator iter
|
|
|
|
|
= locals.mVariables.begin(); iter!=locals.mVariables.end(); ++iter,++index)
|
|
|
|
|
for (std::vector<std::pair<std::string, ESM::Variant> >::const_iterator iter
|
|
|
|
|
= locals.mVariables.begin(); iter!=locals.mVariables.end(); ++iter,++index)
|
|
|
|
|
{
|
|
|
|
|
if (iter->first.empty())
|
|
|
|
|
{
|
|
|
|
|
if (iter->first.empty())
|
|
|
|
|
// no variable names available (this will happen for legacy, i.e. ESS-imported savegames only)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// no variable names available (this will happen for legacy, i.e. ESS-imported savegames only)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (index >= numshorts+numlongs)
|
|
|
|
|
mFloats.at(index - (numshorts+numlongs)) = iter->second.getFloat();
|
|
|
|
|
else if (index >= numshorts)
|
|
|
|
|
mLongs.at(index - numshorts) = iter->second.getInteger();
|
|
|
|
|
else
|
|
|
|
|
mShorts.at(index) = iter->second.getInteger();
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception& e)
|
|
|
|
|
{
|
|
|
|
|
Log(Debug::Error) << "Failed to read local variable state for script '"
|
|
|
|
|
<< script << "' (legacy format): " << e.what()
|
|
|
|
|
<< "\nNum shorts: " << numshorts << " / " << mShorts.size()
|
|
|
|
|
<< " Num longs: " << numlongs << " / " << mLongs.size();
|
|
|
|
|
}
|
|
|
|
|
if (index >= numshorts+numlongs)
|
|
|
|
|
mFloats.at(index - (numshorts+numlongs)) = iter->second.getFloat();
|
|
|
|
|
else if (index >= numshorts)
|
|
|
|
|
mLongs.at(index - numshorts) = iter->second.getInteger();
|
|
|
|
|
else
|
|
|
|
|
mShorts.at(index) = iter->second.getInteger();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
catch (std::exception& e)
|
|
|
|
|
{
|
|
|
|
|
char type = declarations.getType (iter->first);
|
|
|
|
|
int index2 = declarations.getIndex (iter->first);
|
|
|
|
|
Log(Debug::Error) << "Failed to read local variable state for script '"
|
|
|
|
|
<< script << "' (legacy format): " << e.what()
|
|
|
|
|
<< "\nNum shorts: " << numshorts << " / " << mShorts.size()
|
|
|
|
|
<< " Num longs: " << numlongs << " / " << mLongs.size();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char type = declarations.getType (iter->first);
|
|
|
|
|
int index2 = declarations.getIndex (iter->first);
|
|
|
|
|
|
|
|
|
|
// silently ignore locals that don't exist anymore
|
|
|
|
|
if (type == ' ' || index2 == -1)
|
|
|
|
|
continue;
|
|
|
|
|
// silently ignore locals that don't exist anymore
|
|
|
|
|
if (type == ' ' || index2 == -1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case 's': mShorts.at (index2) = iter->second.getInteger(); break;
|
|
|
|
|
case 'l': mLongs.at (index2) = iter->second.getInteger(); break;
|
|
|
|
|
case 'f': mFloats.at (index2) = iter->second.getFloat(); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
// ignore type changes
|
|
|
|
|
/// \todo write to log
|
|
|
|
|
case 's': mShorts.at (index2) = iter->second.getInteger(); break;
|
|
|
|
|
case 'l': mLongs.at (index2) = iter->second.getInteger(); break;
|
|
|
|
|
case 'f': mFloats.at (index2) = iter->second.getFloat(); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
// ignore type changes
|
|
|
|
|
/// \todo write to log
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const Compiler::SourceException&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|