mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
blacklisting for scripts in OpenMW
This commit is contained in:
parent
e33ee52b91
commit
d87630b41a
7 changed files with 58 additions and 12 deletions
|
@ -180,6 +180,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
|
||||||
, mEncoder(NULL)
|
, mEncoder(NULL)
|
||||||
, mActivationDistanceOverride(-1)
|
, mActivationDistanceOverride(-1)
|
||||||
, mGrab(true)
|
, mGrab(true)
|
||||||
|
, mScriptBlacklistUse (true)
|
||||||
|
|
||||||
{
|
{
|
||||||
std::srand ( std::time(NULL) );
|
std::srand ( std::time(NULL) );
|
||||||
|
@ -406,7 +407,8 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
||||||
mScriptContext->setExtensions (&mExtensions);
|
mScriptContext->setExtensions (&mExtensions);
|
||||||
|
|
||||||
mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
|
mEnvironment.setScriptManager (new MWScript::ScriptManager (MWBase::Environment::get().getWorld()->getStore(),
|
||||||
mVerboseScripts, *mScriptContext, mWarningsMode));
|
mVerboseScripts, *mScriptContext, mWarningsMode,
|
||||||
|
mScriptBlacklistUse ? mScriptBlacklist : std::vector<std::string>()));
|
||||||
|
|
||||||
// Create game mechanics system
|
// Create game mechanics system
|
||||||
MWMechanics::MechanicsManager* mechanics = new MWMechanics::MechanicsManager;
|
MWMechanics::MechanicsManager* mechanics = new MWMechanics::MechanicsManager;
|
||||||
|
@ -565,3 +567,13 @@ void OMW::Engine::setWarningsMode (int mode)
|
||||||
{
|
{
|
||||||
mWarningsMode = mode;
|
mWarningsMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OMW::Engine::setScriptBlacklist (const std::vector<std::string>& list)
|
||||||
|
{
|
||||||
|
mScriptBlacklist = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OMW::Engine::setScriptBlacklistUse (bool use)
|
||||||
|
{
|
||||||
|
mScriptBlacklistUse = use;
|
||||||
|
}
|
|
@ -89,6 +89,8 @@ namespace OMW
|
||||||
Files::Collections mFileCollections;
|
Files::Collections mFileCollections;
|
||||||
bool mFSStrict;
|
bool mFSStrict;
|
||||||
Translation::Storage mTranslationDataStorage;
|
Translation::Storage mTranslationDataStorage;
|
||||||
|
std::vector<std::string> mScriptBlacklist;
|
||||||
|
bool mScriptBlacklistUse;
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
Engine (const Engine&);
|
Engine (const Engine&);
|
||||||
|
@ -181,6 +183,10 @@ namespace OMW
|
||||||
|
|
||||||
void setWarningsMode (int mode);
|
void setWarningsMode (int mode);
|
||||||
|
|
||||||
|
void setScriptBlacklist (const std::vector<std::string>& list);
|
||||||
|
|
||||||
|
void setScriptBlacklistUse (bool use);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Files::ConfigurationManager& mCfgMgr;
|
Files::ConfigurationManager& mCfgMgr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -144,6 +144,12 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||||
"\t1 - show warning but consider script as correctly compiled anyway\n"
|
"\t1 - show warning but consider script as correctly compiled anyway\n"
|
||||||
"\t2 - treat warnings as errors")
|
"\t2 - treat warnings as errors")
|
||||||
|
|
||||||
|
("script-blacklist", bpo::value<StringsVector>()->default_value(StringsVector(), "")
|
||||||
|
->multitoken(), "ignore the specified script (if the use of the blacklist is enabled)")
|
||||||
|
|
||||||
|
("script-blacklist-use", bpo::value<bool>()->implicit_value(true)
|
||||||
|
->default_value(true), "enable script blacklisting")
|
||||||
|
|
||||||
("skip-menu", bpo::value<bool>()->implicit_value(true)
|
("skip-menu", bpo::value<bool>()->implicit_value(true)
|
||||||
->default_value(false), "skip main menu on game startup")
|
->default_value(false), "skip main menu on game startup")
|
||||||
|
|
||||||
|
@ -241,15 +247,19 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||||
engine.setCell(variables["start"].as<std::string>());
|
engine.setCell(variables["start"].as<std::string>());
|
||||||
engine.setSkipMenu (variables["skip-menu"].as<bool>());
|
engine.setSkipMenu (variables["skip-menu"].as<bool>());
|
||||||
|
|
||||||
// other settings
|
// scripts
|
||||||
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
|
||||||
engine.setScriptsVerbosity(variables["script-verbose"].as<bool>());
|
|
||||||
engine.setCompileAll(variables["script-all"].as<bool>());
|
engine.setCompileAll(variables["script-all"].as<bool>());
|
||||||
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
|
engine.setScriptsVerbosity(variables["script-verbose"].as<bool>());
|
||||||
engine.setScriptConsoleMode (variables["script-console"].as<bool>());
|
engine.setScriptConsoleMode (variables["script-console"].as<bool>());
|
||||||
engine.setStartupScript (variables["script-run"].as<std::string>());
|
engine.setStartupScript (variables["script-run"].as<std::string>());
|
||||||
engine.setActivationDistanceOverride (variables["activate-dist"].as<int>());
|
|
||||||
engine.setWarningsMode (variables["script-warn"].as<int>());
|
engine.setWarningsMode (variables["script-warn"].as<int>());
|
||||||
|
engine.setScriptBlacklist (variables["script-blacklist"].as<StringsVector>());
|
||||||
|
engine.setScriptBlacklistUse (variables["script-blacklist-use"].as<bool>());
|
||||||
|
|
||||||
|
// other settings
|
||||||
|
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
||||||
|
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
|
||||||
|
engine.setActivationDistanceOverride (variables["activate-dist"].as<int>());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <components/esm/loadscpt.hpp>
|
#include <components/esm/loadscpt.hpp>
|
||||||
|
|
||||||
|
@ -22,12 +23,19 @@
|
||||||
namespace MWScript
|
namespace MWScript
|
||||||
{
|
{
|
||||||
ScriptManager::ScriptManager (const MWWorld::ESMStore& store, bool verbose,
|
ScriptManager::ScriptManager (const MWWorld::ESMStore& store, bool verbose,
|
||||||
Compiler::Context& compilerContext, int warningsMode)
|
Compiler::Context& compilerContext, int warningsMode,
|
||||||
|
const std::vector<std::string>& scriptBlacklist)
|
||||||
: mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
|
: mErrorHandler (std::cerr), mStore (store), mVerbose (verbose),
|
||||||
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext),
|
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext),
|
||||||
mOpcodesInstalled (false), mGlobalScripts (store)
|
mOpcodesInstalled (false), mGlobalScripts (store)
|
||||||
{
|
{
|
||||||
mErrorHandler.setWarningsMode (warningsMode);
|
mErrorHandler.setWarningsMode (warningsMode);
|
||||||
|
|
||||||
|
mScriptBlacklist.resize (scriptBlacklist.size());
|
||||||
|
|
||||||
|
std::transform (scriptBlacklist.begin(), scriptBlacklist.end(),
|
||||||
|
mScriptBlacklist.begin(), Misc::StringUtils::lowerCase);
|
||||||
|
std::sort (mScriptBlacklist.begin(), mScriptBlacklist.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptManager::compile (const std::string& name)
|
bool ScriptManager::compile (const std::string& name)
|
||||||
|
@ -133,11 +141,17 @@ namespace MWScript
|
||||||
int success = 0;
|
int success = 0;
|
||||||
|
|
||||||
const MWWorld::Store<ESM::Script>& scripts = mStore.get<ESM::Script>();
|
const MWWorld::Store<ESM::Script>& scripts = mStore.get<ESM::Script>();
|
||||||
MWWorld::Store<ESM::Script>::iterator it = scripts.begin();
|
|
||||||
|
|
||||||
for (; it != scripts.end(); ++it, ++count)
|
for (MWWorld::Store<ESM::Script>::iterator iter = scripts.begin();
|
||||||
if (compile (it->mId))
|
iter != scripts.end(); ++iter)
|
||||||
++success;
|
if (!std::binary_search (mScriptBlacklist.begin(), mScriptBlacklist.end(),
|
||||||
|
Misc::StringUtils::lowerCase (iter->mId)))
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
|
||||||
|
if (compile (iter->mId))
|
||||||
|
++success;
|
||||||
|
}
|
||||||
|
|
||||||
return std::make_pair (count, success);
|
return std::make_pair (count, success);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,13 @@ namespace MWScript
|
||||||
ScriptCollection mScripts;
|
ScriptCollection mScripts;
|
||||||
GlobalScripts mGlobalScripts;
|
GlobalScripts mGlobalScripts;
|
||||||
std::map<std::string, Compiler::Locals> mOtherLocals;
|
std::map<std::string, Compiler::Locals> mOtherLocals;
|
||||||
|
std::vector<std::string> mScriptBlacklist;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ScriptManager (const MWWorld::ESMStore& store, bool verbose,
|
ScriptManager (const MWWorld::ESMStore& store, bool verbose,
|
||||||
Compiler::Context& compilerContext, int warningsMode);
|
Compiler::Context& compilerContext, int warningsMode,
|
||||||
|
const std::vector<std::string>& scriptBlacklist);
|
||||||
|
|
||||||
virtual void run (const std::string& name, Interpreter::Context& interpreterContext);
|
virtual void run (const std::string& name, Interpreter::Context& interpreterContext);
|
||||||
///< Run the script with the given name (compile first, if not compiled yet)
|
///< Run the script with the given name (compile first, if not compiled yet)
|
||||||
|
|
|
@ -2,3 +2,4 @@ data="?global?data"
|
||||||
data="?mw?Data Files"
|
data="?mw?Data Files"
|
||||||
data-local="?userdata?data"
|
data-local="?userdata?data"
|
||||||
resources=${OPENMW_RESOURCE_FILES}
|
resources=${OPENMW_RESOURCE_FILES}
|
||||||
|
script-blacklist=Museum
|
||||||
|
|
|
@ -3,3 +3,4 @@ data="?mw?Data Files"
|
||||||
data=./data
|
data=./data
|
||||||
data-local="?userdata?data"
|
data-local="?userdata?data"
|
||||||
resources=./resources
|
resources=./resources
|
||||||
|
script-blacklist=Museum
|
||||||
|
|
Loading…
Reference in a new issue