Index: code/trunk/src/core/CMakeLists.txt
===================================================================
--- code/trunk/src/core/CMakeLists.txt	(revision 5693)
+++ code/trunk/src/core/CMakeLists.txt	(revision 5695)
@@ -32,7 +32,9 @@
   GUIManager.cc
   Language.cc
-  LuaBind.cc
+  LuaState.cc
+  MemoryArchive.cc
   ObjectListBase.cc
   OrxonoxClass.cc
+  Resource.cc
   WindowEventListener.cc
 
@@ -77,5 +79,6 @@
   TOLUA_FILES
     CommandExecutor.h
-    LuaBind.h
+    Loader.h
+    LuaState.h
   DEFINE_SYMBOL
     "CORE_SHARED_BUILD"
Index: code/trunk/src/core/Clock.h
===================================================================
--- code/trunk/src/core/Clock.h	(revision 5693)
+++ code/trunk/src/core/Clock.h	(revision 5695)
@@ -21,7 +21,7 @@
  *
  *   Author:
- *      Fabian 'x3n' Landau
+ *      Reto Grieder
  *   Co-authors:
- *      Reto Grieder
+ *      ...
  *
  */
Index: code/trunk/src/core/ConfigFileManager.cc
===================================================================
--- code/trunk/src/core/ConfigFileManager.cc	(revision 5693)
+++ code/trunk/src/core/ConfigFileManager.cc	(revision 5695)
@@ -40,8 +40,4 @@
 namespace orxonox
 {
-    const char* const DEFAULT_CONFIG_FILE = "default.ini";
-
-    ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
-
     SetConsoleCommandShortcutExtern(config).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());
     SetConsoleCommandShortcutExtern(tconfig).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());
@@ -229,6 +225,6 @@
         if (!boost::filesystem::exists(filepath))
         {
-            // Try to get default one from the media folder
-            boost::filesystem::path defaultFilepath(Core::getMediaPath() / "defaultConfig" / this->filename_);
+            // Try to get default one from the data folder
+            boost::filesystem::path defaultFilepath(Core::getDataPath() / "defaultConfig" / this->filename_);
             if (boost::filesystem::exists(defaultFilepath))
             {
@@ -339,8 +335,6 @@
     void ConfigFile::save() const
     {
-        boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
-
         std::ofstream file;
-        file.open(filepath.string().c_str(), std::fstream::out);
+        file.open((Core::getConfigPathString() + filename_).c_str(), std::fstream::out);
         file.setf(std::ios::fixed, std::ios::floatfield);
         file.precision(6);
@@ -479,4 +473,8 @@
     ///////////////////////
 
+    ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
+
+    std::string ConfigFileManager::DEFAULT_CONFIG_FILE = "default.ini";
+
     ConfigFileManager::ConfigFileManager()
          : mininmalFreeType_(ConfigFileType::numberOfReservedTypes)
Index: code/trunk/src/core/ConfigFileManager.h
===================================================================
--- code/trunk/src/core/ConfigFileManager.h	(revision 5693)
+++ code/trunk/src/core/ConfigFileManager.h	(revision 5695)
@@ -307,4 +307,6 @@
             void updateConfigValues(ConfigFileType type);
 
+            static std::string DEFAULT_CONFIG_FILE;
+
         private:
             ConfigFileManager(const ConfigFileManager&);
Index: code/trunk/src/core/ConfigValueContainer.h
===================================================================
--- code/trunk/src/core/ConfigValueContainer.h	(revision 5693)
+++ code/trunk/src/core/ConfigValueContainer.h	(revision 5695)
@@ -31,5 +31,5 @@
     @brief Definition of the ConfigValueContainer class.
 
-    The ConfigValueContainer class contains all needed informations about a configurable variable:
+    The ConfigValueContainer class contains all needed information about a configurable variable:
      - the name of the variable
      - the name of the class the variable belongs to
@@ -79,7 +79,7 @@
 
 
-    //! The ConfigValuecontainer contains all needed informations about a configurable variable.
+    //! The ConfigValuecontainer contains all needed information about a configurable variable.
     /**
-        The ConfigValueContainer class contains all needed informations about a configurable variable:
+        The ConfigValueContainer class contains all needed information about a configurable variable:
          - the name of the variable
          - the name of the class the variable belongs to
Index: code/trunk/src/core/Core.cc
===================================================================
--- code/trunk/src/core/Core.cc	(revision 5693)
+++ code/trunk/src/core/Core.cc	(revision 5695)
@@ -42,5 +42,4 @@
 #include <boost/version.hpp>
 #include <boost/filesystem.hpp>
-#include <OgreRenderWindow.h>
 
 #ifdef ORXONOX_PLATFORM_WINDOWS
@@ -76,5 +75,5 @@
 #include "Identifier.h"
 #include "Language.h"
-#include "LuaBind.h"
+#include "LuaState.h"
 #include "Shell.h"
 #include "TclBind.h"
@@ -94,5 +93,5 @@
     Core* Core::singletonPtr_s  = 0;
 
-    SetCommandLineArgument(mediaPath, "").information("Path to the media/data files");
+    SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
     SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
     SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file");
@@ -119,7 +118,11 @@
             this->setConfigValues();
 
-            // Possible media path override by the command line
-            if (!CommandLine::getArgument("mediaPath")->hasDefaultValue())
-                tsetMediaPath(CommandLine::getValue("mediaPath"));
+            // External data directory only exists for dev runs
+            if (Core::isDevelopmentRun())
+            {
+                // Possible data path override by the command line
+                if (!CommandLine::getArgument("externalDataPath")->hasDefaultValue())
+                    tsetExternalDataPath(CommandLine::getValue("externalDataPath"));
+            }
         }
 
@@ -154,12 +157,4 @@
                 .description("If true, all random actions are different each time you start the game")
                 .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);
-
-            // Only show this config value for development builds
-            if (Core::isDevelopmentRun())
-            {
-                SetConfigValue(mediaPathString_, mediaPath_.string())
-                    .description("Relative path to the game data.")
-                    .callback(this, &CoreConfiguration::mediaPathChanged);
-            }
         }
 
@@ -192,13 +187,4 @@
 
         /**
-        @brief
-            Callback function if the media path has changed.
-        */
-        void mediaPathChanged()
-        {
-            mediaPath_ = boost::filesystem::path(this->mediaPathString_);
-        }
-
-        /**
             @brief Sets the language in the config-file back to the default.
         */
@@ -210,20 +196,11 @@
         /**
         @brief
-            Temporary sets the media path
+            Temporary sets the data path
         @param path
-            The new media path
+            The new data path
         */
-        void tsetMediaPath(const std::string& path)
-        {
-            if (Core::isDevelopmentRun())
-            {
-                ModifyConfigValue(mediaPathString_, tset, path);
-            }
-            else
-            {
-                // Manual 'config' value without the file entry
-                mediaPathString_ = path;
-                this->mediaPathChanged();
-            }
+        void tsetExternalDataPath(const std::string& path)
+        {
+            dataPath_ = boost::filesystem::path(path);
         }
 
@@ -245,5 +222,4 @@
         std::string language_;                          //!< The language
         bool bInitializeRandomNumberGenerator_;         //!< If true, srand(time(0)) is called
-        std::string mediaPathString_;                   //!< Path to the data/media file folder as string
 
         //! Path to the parent directory of the ones above if program was installed with relativ pahts
@@ -251,5 +227,6 @@
         boost::filesystem::path executablePath_;        //!< Path to the executable
         boost::filesystem::path modulePath_;            //!< Path to the modules
-        boost::filesystem::path mediaPath_;             //!< Path to the media file folder
+        boost::filesystem::path dataPath_;              //!< Path to the data file folder
+        boost::filesystem::path externalDataPath_;      //!< Path to the external data file folder
         boost::filesystem::path configPath_;            //!< Path to the config file folder
         boost::filesystem::path logPath_;               //!< Path to the log file folder
@@ -276,5 +253,5 @@
         {
             // We search for helper files with the following extension
-            std::string moduleextension = ORXONOX_MODULE_EXTENSION;
+            std::string moduleextension = specialConfig::moduleExtension;
             size_t moduleextensionlength = moduleextension.size();
 
@@ -364,25 +341,25 @@
         this->languageInstance_.reset(new Language());
 
+        // creates the class hierarchy for all classes with factories
+        Factory::createClassHierarchy();
+
         // Do this soon after the ConfigFileManager has been created to open up the
         // possibility to configure everything below here
         this->configuration_->initialise();
 
-        // Create the lua interface
-        this->luaBind_.reset(new LuaBind());
+        // Load OGRE excluding the renderer and the render window
+        this->graphicsManager_.reset(new GraphicsManager(false));
 
         // initialise Tcl
-        this->tclBind_.reset(new TclBind(Core::getMediaPathString()));
+        this->tclBind_.reset(new TclBind(Core::getDataPathString()));
         this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
 
         // create a shell
         this->shell_.reset(new Shell());
-
-        // creates the class hierarchy for all classes with factories
-        Factory::createClassHierarchy();
     }
 
     /**
     @brief
-        All destruction code is handled by scoped_ptrs and SimpleScopeGuards.
+        All destruction code is handled by scoped_ptrs and ScopeGuards.
     */
     Core::~Core()
@@ -392,23 +369,18 @@
     void Core::loadGraphics()
     {
-        if (bGraphicsLoaded_)
-            return;
-
-        // Load OGRE including the render window
-        scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());
-
-        // The render window width and height are used to set up the mouse movement.
-        size_t windowHnd = 0;
-        graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
+        // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
+        Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
+
+        // Upgrade OGRE to receive a render window
+        graphicsManager_->upgradeToGraphics();
 
         // Calls the InputManager which sets up the input devices.
-        scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));
+        inputManager_.reset(new InputManager());
 
         // load the CEGUI interface
-        guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow()));
-
-        // Dismiss scoped pointers
-        graphicsManager_.swap(graphicsManager);
-        inputManager_.swap(inputManager);
+        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
+            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
+
+        unloader.Dismiss();
 
         bGraphicsLoaded_ = true;
@@ -417,10 +389,18 @@
     void Core::unloadGraphics()
     {
-        if (!bGraphicsLoaded_)
-            return;
-
         this->guiManager_.reset();;
         this->inputManager_.reset();;
         this->graphicsManager_.reset();
+
+        // Load Ogre::Root again, but without the render system
+        try
+            { this->graphicsManager_.reset(new GraphicsManager(false)); }
+        catch (...)
+        {
+            COUT(0) << "An exception occurred during 'new GraphicsManager' while "
+                    << "another exception was being handled. This will lead to undefined behaviour!" << std::endl
+                    << "Terminating the program." << std::endl;
+            abort();
+        }
 
         bGraphicsLoaded_ = false;
@@ -485,16 +465,25 @@
     }
 
-    /*static*/ void Core::tsetMediaPath(const std::string& path)
-    {
-        getInstance().configuration_->tsetMediaPath(path);
-    }
-
-    /*static*/ const boost::filesystem::path& Core::getMediaPath()
-    {
-        return getInstance().configuration_->mediaPath_;
-    }
-    /*static*/ std::string Core::getMediaPathString()
-    {
-        return getInstance().configuration_->mediaPath_.string() + '/';
+    /*static*/ void Core::tsetExternalDataPath(const std::string& path)
+    {
+        getInstance().configuration_->tsetExternalDataPath(path);
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getDataPath()
+    {
+        return getInstance().configuration_->dataPath_;
+    }
+    /*static*/ std::string Core::getDataPathString()
+    {
+        return getInstance().configuration_->dataPath_.string() + '/';
+    }
+
+    /*static*/ const boost::filesystem::path& Core::getExternalDataPath()
+    {
+        return getInstance().configuration_->externalDataPath_;
+    }
+    /*static*/ std::string Core::getExternalDataPathString()
+    {
+        return getInstance().configuration_->externalDataPath_.string() + '/';
     }
 
@@ -638,5 +627,5 @@
             COUT(1) << "Running from the build tree." << std::endl;
             Core::bDevRun_ = true;
-            configuration_->modulePath_ = ORXONOX_MODULE_DEV_PATH;
+            configuration_->modulePath_ = specialConfig::moduleDevDirectory;
         }
         else
@@ -646,5 +635,5 @@
 
             // Also set the root path
-            boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
+            boost::filesystem::path relativeExecutablePath(specialConfig::defaultRuntimePath);
             configuration_->rootPath_ = configuration_->executablePath_;
             while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_)
@@ -655,5 +644,5 @@
 
             // Module path is fixed as well
-            configuration_->modulePath_ = configuration_->rootPath_ / ORXONOX_MODULE_INSTALL_PATH;
+            configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;
 
 #else
@@ -661,5 +650,5 @@
             // There is no root path, so don't set it at all
             // Module path is fixed as well
-            configuration_->modulePath_ = ORXONOX_MODULE_INSTALL_PATH;
+            configuration_->modulePath_ = specialConfig::moduleInstallDirectory;
 
 #endif
@@ -677,7 +666,8 @@
         if (Core::isDevelopmentRun())
         {
-            configuration_->mediaPath_  = ORXONOX_MEDIA_DEV_PATH;
-            configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH;
-            configuration_->logPath_    = ORXONOX_LOG_DEV_PATH;
+            configuration_->dataPath_  = specialConfig::dataDevDirectory;
+            configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory;
+            configuration_->configPath_ = specialConfig::configDevDirectory;
+            configuration_->logPath_    = specialConfig::logDevDirectory;
         }
         else
@@ -687,11 +677,11 @@
 
             // Using paths relative to the install prefix, complete them
-            configuration_->mediaPath_  = configuration_->rootPath_ / ORXONOX_MEDIA_INSTALL_PATH;
-            configuration_->configPath_ = configuration_->rootPath_ / ORXONOX_CONFIG_INSTALL_PATH;
-            configuration_->logPath_    = configuration_->rootPath_ / ORXONOX_LOG_INSTALL_PATH;
+            configuration_->dataPath_   = configuration_->rootPath_ / specialConfig::defaultDataPath;
+            configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath;
+            configuration_->logPath_    = configuration_->rootPath_ / specialConfig::defaultLogPath;
 
 #else
 
-            configuration_->mediaPath_  = ORXONOX_MEDIA_INSTALL_PATH;
+            configuration_->dataPath_  = specialConfig::dataInstallDirectory;
 
             // Get user directory
@@ -706,6 +696,6 @@
             userDataPath /= ".orxonox";
 
-            configuration_->configPath_ = userDataPath / ORXONOX_CONFIG_INSTALL_PATH;
-            configuration_->logPath_    = userDataPath / ORXONOX_LOG_INSTALL_PATH;
+            configuration_->configPath_ = userDataPath / specialConfig::defaultConfigPath;
+            configuration_->logPath_    = userDataPath / specialConfig::defaultLogPath;
 
 #endif
@@ -741,54 +731,24 @@
     }
 
-    bool Core::preUpdate(const Clock& time) throw()
-    {
-        std::string exceptionMessage;
-        try
-        {
-            if (this->bGraphicsLoaded_)
-            {
-                // process input events
-                this->inputManager_->update(time);
-                // process gui events
-                this->guiManager_->update(time);
-            }
-            // process thread commands
-            this->tclThreadManager_->update(time);
-        }
-        catch (const std::exception& ex)
-        { exceptionMessage = ex.what(); }
-        catch (...)
-        { exceptionMessage = "Unknown exception"; }
-        if (!exceptionMessage.empty())
-        {
-            COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl;
-            COUT(0) << "This should really never happen! Closing the program." << std::endl;
-            return false;
-        }
-        return true;
-    }
-
-    bool Core::postUpdate(const Clock& time) throw()
-    {
-        std::string exceptionMessage;
-        try
-        {
-            if (this->bGraphicsLoaded_)
-            {
-                // Render (doesn't throw)
-                this->graphicsManager_->update(time);
-            }
-        }
-        catch (const std::exception& ex)
-        { exceptionMessage = ex.what(); }
-        catch (...)
-        { exceptionMessage = "Unknown exception"; }
-        if (!exceptionMessage.empty())
-        {
-            COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl;
-            COUT(0) << "This should really never happen! Closing the program." << std::endl;
-            return false;
-        }
-        return true;
+    void Core::preUpdate(const Clock& time)
+    {
+        if (this->bGraphicsLoaded_)
+        {
+            // process input events
+            this->inputManager_->update(time);
+            // process gui events
+            this->guiManager_->update(time);
+        }
+        // process thread commands
+        this->tclThreadManager_->update(time);
+    }
+
+    void Core::postUpdate(const Clock& time)
+    {
+        if (this->bGraphicsLoaded_)
+        {
+            // Render (doesn't throw)
+            this->graphicsManager_->update(time);
+        }
     }
 }
Index: code/trunk/src/core/Core.h
===================================================================
--- code/trunk/src/core/Core.h	(revision 5693)
+++ code/trunk/src/core/Core.h	(revision 5695)
@@ -51,5 +51,4 @@
 {
     class CoreConfiguration;
-    using boost::scoped_ptr;
 
     /**
@@ -57,5 +56,5 @@
         The Core class is a singleton used to configure the program basics.
     @details
-        The class provides information about the media, config and log path.
+        The class provides information about the data, config and log path.
         It determines those by the use of platform specific functions.
     @remark
@@ -66,4 +65,5 @@
         typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;
         friend class Singleton<Core>;
+        friend class Game;
 
         public:
@@ -80,10 +80,4 @@
             void setConfigValues();
 
-            bool preUpdate(const Clock& time) throw();
-            bool postUpdate(const Clock& time) throw();
-
-            void loadGraphics();
-            void unloadGraphics();
-
             static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
             static void  setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
@@ -91,7 +85,9 @@
             static void  resetLanguage();
 
-            static void tsetMediaPath(const std::string& path);
-            //! Returns the path to the config files as boost::filesystem::path
-            static const boost::filesystem::path& getMediaPath();
+            static void tsetExternalDataPath(const std::string& path);
+            //! Returns the path to the data files as boost::filesystem::path
+            static const boost::filesystem::path& getDataPath();
+            //! Returns the path to the external data files as boost::filesystem::path
+            static const boost::filesystem::path& getExternalDataPath();
             //! Returns the path to the config files as boost::filesystem::path
             static const boost::filesystem::path& getConfigPath();
@@ -101,5 +97,7 @@
             static const boost::filesystem::path& getRootPath();
             //! Returns the path to the data files as std::string
-            static std::string getMediaPathString();
+            static std::string getDataPathString();
+            //! Returns the path to the external data files as std::string
+            static std::string getExternalDataPathString();
             //! Returns the path to the config files as std::string
             static std::string getConfigPathString();
@@ -113,4 +111,10 @@
         private:
             Core(const Core&); //!< Don't use (undefined symbol)
+
+            void preUpdate(const Clock& time);
+            void postUpdate(const Clock& time);
+
+            void loadGraphics();
+            void unloadGraphics();
 
             void setFixedPaths();
@@ -126,5 +130,4 @@
             scoped_ptr<Language>          languageInstance_;
             scoped_ptr<CoreConfiguration> configuration_;
-            scoped_ptr<LuaBind>           luaBind_;
             scoped_ptr<TclBind>           tclBind_;
             scoped_ptr<TclThreadManager>  tclThreadManager_;
Index: code/trunk/src/core/CorePrereqs.h
===================================================================
--- code/trunk/src/core/CorePrereqs.h	(revision 5693)
+++ code/trunk/src/core/CorePrereqs.h	(revision 5695)
@@ -135,5 +135,7 @@
     class LanguageEntry;
     class Loader;
-    class LuaBind;
+    class LuaState;
+    class MemoryArchive;
+    class MemoryArchiveFactory;
     class MetaObjectList;
     class MetaObjectListElement;
@@ -150,4 +152,5 @@
     class OgreWindowEventListener;
     class OrxonoxClass;
+    struct ResourceInfo;
     class Shell;
     class ShellListener;
@@ -225,4 +228,18 @@
 }
 
+// Ogre
+namespace Ogre
+{
+    class DataStream;
+    template <class T> class SharedPtr;
+    typedef SharedPtr<DataStream> DataStreamPtr;
+}
+namespace orxonox
+{
+    // Import the Ogre::DataStream
+    using Ogre::DataStream;
+    using Ogre::DataStreamPtr;
+}
+
 // CEGUI
 namespace CEGUI
Index: code/trunk/src/core/DynLibManager.h
===================================================================
--- code/trunk/src/core/DynLibManager.h	(revision 5693)
+++ code/trunk/src/core/DynLibManager.h	(revision 5695)
@@ -34,4 +34,7 @@
 
 #include "CorePrereqs.h"
+
+#include <map>
+#include <string>
 #include "util/Singleton.h"
 
Index: code/trunk/src/core/GUIManager.cc
===================================================================
--- code/trunk/src/core/GUIManager.cc	(revision 5693)
+++ code/trunk/src/core/GUIManager.cc	(revision 5695)
@@ -27,10 +27,4 @@
  *
  */
-
-/**
-@file
-@brief
-    Implementation of the GUIManager class.
-*/
 
 #include "GUIManager.h"
@@ -43,4 +37,5 @@
 #include <CEGUIExceptions.h>
 #include <CEGUIInputEvent.h>
+#include <CEGUIMouseCursor.h>
 #include <CEGUIResourceProvider.h>
 #include <CEGUISystem.h>
@@ -59,5 +54,6 @@
 #include "Core.h"
 #include "Clock.h"
-#include "LuaBind.h"
+#include "LuaState.h"
+#include "Resource.h"
 
 namespace orxonox
@@ -101,5 +97,5 @@
     @return true if success, otherwise false
     */
-    GUIManager::GUIManager(Ogre::RenderWindow* renderWindow)
+    GUIManager::GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen)
         : renderWindow_(renderWindow)
         , resourceProvider_(0)
@@ -109,70 +105,42 @@
         COUT(3) << "Initialising CEGUI." << std::endl;
 
-        try
-        {
-            // Note: No SceneManager specified yet
-            guiRenderer_.reset(new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
-            resourceProvider_ = guiRenderer_->createResourceProvider();
-            resourceProvider_->setDefaultResourceGroup("GUI");
-
-            // setup scripting
-            scriptModule_.reset(new LuaScriptModule());
-            luaState_ = scriptModule_->getLuaState();
-
-            // Create our own logger to specify the filepath
-            std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
-            ceguiLogger->setLogFilename(Core::getLogPathString() + "cegui.log");
-            // set the log level according to ours (translate by subtracting 1)
-            ceguiLogger->setLoggingLevel(
-                static_cast<LoggingLevel>(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1));
-            this->ceguiLogger_ = ceguiLogger.release();
-
-            // create the CEGUI system singleton
-            guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
-
-            // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place
-            LuaBind::getInstance().openToluaInterfaces(this->luaState_);
-
-            // initialise the basic lua code
-            this->loadLuaCode();
-        }
-        catch (CEGUI::Exception& ex)
-        {
-#if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6
-            throw GeneralException(ex.getMessage().c_str());
-#else
-            throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
-                ex.getFileName().c_str(), ex.getName().c_str());
-#endif
-        }
-    }
-
-    /**
-    @brief
-        Destructor of the GUIManager
-
+        // Note: No SceneManager specified yet
+        guiRenderer_.reset(new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
+        resourceProvider_ = guiRenderer_->createResourceProvider();
+        resourceProvider_->setDefaultResourceGroup("GUI");
+
+        // setup scripting
+        luaState_.reset(new LuaState());
+        scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState()));
+
+        // Create our own logger to specify the filepath
+        std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
+        ceguiLogger->setLogFilename(Core::getLogPathString() + "cegui.log");
+        // set the log level according to ours (translate by subtracting 1)
+        ceguiLogger->setLoggingLevel(
+            static_cast<LoggingLevel>(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1));
+        this->ceguiLogger_ = ceguiLogger.release();
+
+        // create the CEGUI system singleton
+        guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
+
+        // Initialise the basic lua code
+        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
+        this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
+
+        // Align CEGUI mouse with OIS mouse
+        guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);
+
+        // Hide the mouse cursor unless playing in fullscreen mode
+        if (!bFullScreen)
+            CEGUI::MouseCursor::getSingleton().hide();
+    }
+
+    /**
+    @brief
         Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules.
     */
     GUIManager::~GUIManager()
     {
-        // destroy our own tolua interfaces
-        LuaBind::getInstance().closeToluaInterfaces(this->luaState_);
-    }
-
-    /**
-    @brief
-        Calls main Lua script
-    @todo
-        This function calls the main Lua script for our GUI.
-
-        Additionally we set the datapath variable in Lua. This is needed so Lua can access the data used for the GUI.
-    */
-    void GUIManager::loadLuaCode()
-    {
-        // set datapath for GUI data
-        lua_pushfstring(this->scriptModule_->getLuaState(), Core::getMediaPathString().c_str());
-        lua_setglobal(this->scriptModule_->getLuaState(), "datapath");
-        // call main Lua script
-        this->scriptModule_->executeScriptFile("loadGUI_3.lua", "GUI");
     }
 
@@ -221,16 +189,5 @@
     void GUIManager::executeCode(const std::string& str)
     {
-        try
-        {
-            this->scriptModule_->executeString(str);
-        }
-        catch (const CEGUI::Exception& ex)
-        {
-            COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl;
-        }
-        catch (...)
-        {
-            COUT(2) << "Couldn't execute GUI related Lua code due to unknown reasons." << std::endl;
-        }
+        this->luaState_->doString(str, rootFileInfo_);
     }
 
@@ -246,5 +203,5 @@
     void GUIManager::showGUI(const std::string& name)
     {
-        this->executeCode(std::string("showGUI(\"") + name + "\")");
+        this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_);
     }
 
@@ -305,5 +262,5 @@
     void GUIManager::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
     {
-        guiSystem_->injectMouseMove(static_cast<float>(rel.x), static_cast<float>(rel.y));
+        guiSystem_->injectMousePosition(static_cast<float>(abs.x), static_cast<float>(abs.y));
     }
     void GUIManager::mouseScrolled(int abs, int rel)
Index: code/trunk/src/core/GUIManager.h
===================================================================
--- code/trunk/src/core/GUIManager.h	(revision 5693)
+++ code/trunk/src/core/GUIManager.h	(revision 5695)
@@ -28,10 +28,4 @@
  */
 
-/**
-@file
-@brief
-    Declaration of the GUIManager class.
-*/
-
 #ifndef _GUIManager_H__
 #define _GUIManager_H__
@@ -43,4 +37,5 @@
 #include <CEGUIForwardRefs.h>
 #include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
 
 #include "util/OgreForwardRefs.h"
@@ -67,5 +62,5 @@
         friend class Singleton<GUIManager>;
     public:
-        GUIManager(Ogre::RenderWindow* renderWindow);
+        GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen);
         ~GUIManager();
 
@@ -87,6 +82,4 @@
         GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
 
-        void loadLuaCode();
-
         // keyHandler functions
         void keyPressed (const KeyEvent& evt);
@@ -99,14 +92,15 @@
         void mouseScrolled (int abs, int rel);
 
-        boost::scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;       //!< CEGUI's interface to the Ogre Engine
-        boost::scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_;      //!< CEGUI's script module to use Lua
-        boost::scoped_ptr<CEGUI::System>            guiSystem_;         //!< CEGUI's main system
-        Ogre::RenderWindow*                         renderWindow_;      //!< Ogre's render window to give CEGUI access to it
-        CEGUI::ResourceProvider*                    resourceProvider_;  //!< CEGUI's resource provider
-        CEGUI::Logger*                              ceguiLogger_;       //!< CEGUI's logger to be able to log CEGUI errors in our log
-        lua_State*                                  luaState_;          //!< Lua state, access point to the Lua engine
-        std::map<std::string, PlayerInfo*>          players_;           //!< Stores the player (owner) for each gui
+        scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;      //!< CEGUI's interface to the Ogre Engine
+        scoped_ptr<LuaState>                 luaState_;         //!< LuaState, access point to the Lua engine
+        scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_;     //!< CEGUI's script module to use Lua
+        scoped_ptr<CEGUI::System>            guiSystem_;        //!< CEGUI's main system
+        shared_ptr<ResourceInfo>             rootFileInfo_;     //!< Resource information about the root script
+        Ogre::RenderWindow*                  renderWindow_;     //!< Ogre's render window to give CEGUI access to it
+        CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
+        CEGUI::Logger*                       ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
+        std::map<std::string, PlayerInfo*>   players_;          //!< Stores the player (owner) for each gui
 
-        static GUIManager*                          singletonPtr_s;     //!< Singleton reference to GUIManager
+        static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
 
     };
Index: code/trunk/src/core/Game.cc
===================================================================
--- code/trunk/src/core/Game.cc	(revision 5693)
+++ code/trunk/src/core/Game.cc	(revision 5695)
@@ -37,4 +37,5 @@
 #include <exception>
 #include <boost/weak_ptr.hpp>
+#include <CEGUIExceptions.h>
 
 #include "util/Debug.h"
@@ -54,7 +55,4 @@
 namespace orxonox
 {
-    using boost::shared_ptr;
-    using boost::weak_ptr;
-
     static void stop_game()
         { Game::getInstance().stop(); }
@@ -202,6 +200,10 @@
 
             // Core preUpdate (doesn't throw)
-            if (!this->core_->preUpdate(*this->gameClock_))
-            {
+            try
+                { this->core_->preUpdate(*this->gameClock_); }
+            catch (...)
+            {
+                COUT(0) << "An exception occurred in the Core preUpdate: " << Game::getExceptionMessage() << std::endl;
+                COUT(0) << "This should really never happen! Closing the program." << std::endl;
                 this->stop();
                 break;
@@ -212,6 +214,10 @@
 
             // Core postUpdate (doesn't throw)
-            if (!this->core_->postUpdate(*this->gameClock_))
-            {
+            try
+                { this->core_->postUpdate(*this->gameClock_); }
+            catch (...)
+            {
+            COUT(0) << "An exception occurred in the Core postUpdate: " << Game::getExceptionMessage() << std::endl;
+            COUT(0) << "This should really never happen! Closing the program." << std::endl;
                 this->stop();
                 break;
@@ -246,10 +252,10 @@
                     this->loadState(requestedStateNode->name_);
                 }
-                catch (const std::exception& ex)
+                catch (...)
                 {
-                    COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << ex.what() << std::endl;
+                    COUT(1) << "Error: Loading GameState '" << requestedStateNode->name_ << "' failed: " << Game::getExceptionMessage() << std::endl;
                     // All scheduled operations have now been rendered inert --> flush them and issue a warning
                     if (this->requestedStateNodes_.size() > 1)
-                        COUT(1) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl;
+                        COUT(4) << "All " << this->requestedStateNodes_.size() - 1 << " scheduled transitions have been ignored." << std::endl;
                     this->requestedStateNodes_.clear();
                     break;
@@ -267,9 +273,8 @@
             it != this->loadedStates_.end(); ++it)
         {
-            std::string exceptionMessage;
             try
             {
                 // Add tick time for most of the states
-                uint64_t timeBeforeTick;
+                uint64_t timeBeforeTick = 0;
                 if ((*it)->getInfo().bIgnoreTickTime)
                     timeBeforeTick = this->gameClock_->getRealMicroseconds();
@@ -278,11 +283,7 @@
                     this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
             }
-            catch (const std::exception& ex)
-            { exceptionMessage = ex.what(); }
             catch (...)
-            { exceptionMessage = "Unknown exception"; }
-            if (!exceptionMessage.empty())
-            {
-                COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << exceptionMessage << std::endl;
+            {
+                COUT(1) << "An exception occurred while updating '" << (*it)->getName() << "': " << Game::getExceptionMessage() << std::endl;
                 COUT(1) << "This should really never happen!" << std::endl;
                 COUT(1) << "Unloading all GameStates depending on the one that crashed." << std::endl;
@@ -590,16 +591,46 @@
             state->deactivate();
         }
+        catch (...)
+        {
+            COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << Game::getExceptionMessage() << std::endl;
+            COUT(2) << "         There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl;
+        }
+        // Check if graphics is still required
+        if (!bAbort_)
+        {
+            bool graphicsRequired = false;
+            for (unsigned i = 0; i < loadedStates_.size(); ++i)
+                graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
+            if (!graphicsRequired)
+                this->unloadGraphics();
+        }
+        this->bChangingState_ = false;
+    }
+
+    /*static*/ std::string Game::getExceptionMessage()
+    {
+        std::string exceptionMessage;
+        try
+        {
+            // rethrow
+            throw;
+        }
         catch (const std::exception& ex)
         {
-            COUT(2) << "Warning: Unloading GameState '" << name << "' threw an exception: " << ex.what() << std::endl;
-            COUT(2) << "         There might be potential resource leaks involved! To avoid this, improve exception-safety." << std::endl;
-        }
-        // Check if graphics is still required
-        bool graphicsRequired = false;
-        for (unsigned i = 0; i < loadedStates_.size(); ++i)
-            graphicsRequired |= loadedStates_[i]->getInfo().bGraphicsMode;
-        if (!graphicsRequired)
-            this->unloadGraphics();
-        this->bChangingState_ = false;
+            return ex.what();
+        }
+        catch (const CEGUI::Exception& ex)
+        {
+#if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6
+            return GeneralException(ex.getMessage().c_str()).getDescription();
+#else
+            return GeneralException(ex.getMessage().c_str(), ex.getLine(),
+                ex.getFileName().c_str(), ex.getName().c_str()).getDescription();
+#endif
+        }
+        catch (...)
+        {
+            return "Unknown exception";
+        }
     }
 
Index: code/trunk/src/core/Game.h
===================================================================
--- code/trunk/src/core/Game.h	(revision 5693)
+++ code/trunk/src/core/Game.h	(revision 5695)
@@ -62,6 +62,4 @@
 {
     class GameConfiguration;
-    using boost::scoped_ptr;
-    using boost::shared_ptr;
 
     //! Helper object required before GameStates are being constructed
@@ -85,5 +83,5 @@
         typedef std::vector<shared_ptr<GameState> > GameStateVector;
         typedef std::map<std::string, shared_ptr<GameState> > GameStateMap;
-        typedef boost::shared_ptr<GameStateTreeNode> GameStateTreeNodePtr;
+        typedef shared_ptr<GameStateTreeNode> GameStateTreeNodePtr;
 
     public:
@@ -157,4 +155,11 @@
         // ScopeGuard helper function
         void resetChangingState() { this->bChangingState_ = false; }
+        /**
+        @brief
+            Retrieves information from an exception caught with "..."
+        @remarks
+            Never ever call this function without an exception in the stack!
+        */
+        static std::string getExceptionMessage();
 
         scoped_ptr<Clock>                  gameClock_;
Index: code/trunk/src/core/GraphicsManager.cc
===================================================================
--- code/trunk/src/core/GraphicsManager.cc	(revision 5693)
+++ code/trunk/src/core/GraphicsManager.cc	(revision 5695)
@@ -28,25 +28,19 @@
  */
 
-/**
-@file
-@brief
-    Implementation of an partial interface to Ogre.
-*/
-
 #include "GraphicsManager.h"
 
 #include <fstream>
-#include <memory>
+#include <sstream>
 #include <boost/filesystem.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <OgreCompositorManager.h>
-#include <OgreConfigFile.h>
+#include <boost/shared_array.hpp>
+
+#include <OgreArchiveFactory.h>
+#include <OgreArchiveManager.h>
 #include <OgreFrameListener.h>
 #include <OgreRoot.h>
 #include <OgreLogManager.h>
-#include <OgreException.h>
 #include <OgreRenderWindow.h>
 #include <OgreRenderSystem.h>
+#include <OgreResourceGroupManager.h>
 #include <OgreTextureManager.h>
 #include <OgreViewport.h>
@@ -64,10 +58,11 @@
 #include "Game.h"
 #include "GameMode.h"
+#include "Loader.h"
+#include "MemoryArchive.h"
 #include "WindowEventListener.h"
+#include "XMLFile.h"
 
 namespace orxonox
 {
-    using boost::shared_ptr;
-
     class OgreWindowEventListener : public Ogre::WindowEventListener
     {
@@ -89,10 +84,11 @@
         Non-initialising constructor.
     */
-    GraphicsManager::GraphicsManager()
-        : ogreRoot_(0)
-        , ogreLogger_(0)
+    GraphicsManager::GraphicsManager(bool bLoadRenderer)
+        : ogreWindowEventListener_(new OgreWindowEventListener())
+#if OGRE_VERSION < 0x010600
+        , memoryArchiveFactory_(new MemoryArchiveFactory())
+#endif
         , renderWindow_(0)
         , viewport_(0)
-        , ogreWindowEventListener_(new OgreWindowEventListener())
     {
         RegisterObject(GraphicsManager);
@@ -100,32 +96,29 @@
         this->setConfigValues();
 
-        // Ogre setup procedure
-        setupOgre();
-
-        try
-        {
-            // load all the required plugins for Ogre
-            loadOgrePlugins();
-            // read resource declaration file
-            this->declareResources();
-            // Reads ogre config and creates the render window
-            this->loadRenderer();
-
-            // TODO: Spread this
-            this->initialiseResources();
-
-            // add console commands
-            FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
-            functor1->setObject(this);
-            ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
-            CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
-        }
-        catch (...)
-        {
-            // clean up
-            delete this->ogreRoot_;
-            delete this->ogreLogger_;
-            delete this->ogreWindowEventListener_;
-            throw;
+        // Ogre setup procedure (creating Ogre::Root)
+        this->loadOgreRoot();
+        // load all the required plugins for Ogre
+        this->loadOgrePlugins();
+
+        // At first, add the root paths of the data directories as resource locations
+        Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getDataPathString(), "FileSystem", "dataRoot", false);
+        // Load resources
+        resources_.reset(new XMLFile("resources.oxr", "dataRoot"));
+        resources_->setLuaSupport(false);
+        Loader::open(resources_.get());
+
+        // Only for development runs
+        if (Core::isDevelopmentRun())
+        {
+            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getExternalDataPathString(), "FileSystem", "externalDataRoot", false);
+            extResources_.reset(new XMLFile("resources.oxr", "externalDataRoot"));
+            extResources_->setLuaSupport(false);
+            Loader::open(extResources_.get());
+        }
+
+        if (bLoadRenderer)
+        {
+            // Reads the ogre config and creates the render window
+            this->upgradeToGraphics();
         }
     }
@@ -133,33 +126,19 @@
     /**
     @brief
-        Destroys all the Ogre related objects
+        Destruction is done by the member scoped_ptrs.
     */
     GraphicsManager::~GraphicsManager()
     {
-/*
-        delete this->ccPrintScreen_;
-*/
-
-        // unload all compositors (this is only necessary because we don't yet destroy all resources!)
-        Ogre::CompositorManager::getSingleton().removeAll();
-
-        // Delete OGRE main control organ
-        delete this->ogreRoot_;
-
-        // delete the logManager (since we have created it in the first place).
-        delete this->ogreLogger_;
-
-        delete this->ogreWindowEventListener_;
+        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
+        // TODO: Destroy the console command
     }
 
     void GraphicsManager::setConfigValues()
     {
-        SetConfigValue(resourceFile_,    "resources.cfg")
-            .description("Location of the resources file in the data path.");
         SetConfigValue(ogreConfigFile_,  "ogre.cfg")
             .description("Location of the Ogre config file");
-        SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER)
+        SetConfigValue(ogrePluginsDirectory_, specialConfig::ogrePluginsDirectory)
             .description("Folder where the Ogre plugins are located.");
-        SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
+        SetConfigValue(ogrePlugins_, specialConfig::ogrePlugins)
             .description("Comma separated list of all plugins to load.");
         SetConfigValue(ogreLogFile_,     "ogre.log")
@@ -173,4 +152,170 @@
     }
 
+    /**
+    @brief
+        Loads the renderer and creates the render window if not yet done so.
+    @remarks
+        This operation is irreversible without recreating the GraphicsManager!
+        So if it throws you HAVE to recreate the GraphicsManager!!!
+        It therefore offers almost no exception safety.
+    */
+    void GraphicsManager::upgradeToGraphics()
+    {
+        if (renderWindow_ != NULL)
+            return;
+
+        this->loadRenderer();
+
+#if OGRE_VERSION < 0x010600
+        // WORKAROUND: There is an incompatibility for particle scripts when trying
+        // to support both Ogre 1.4 and 1.6. The hacky solution is to create
+        // scripts for the 1.6 version and then remove the inserted "particle_system"
+        // keyword. But we need to supply these new scripts as well, which is why
+        // there is an extra Ogre::Archive dealing with in the memory.
+        using namespace Ogre;
+        ArchiveManager::getSingleton().addArchiveFactory(memoryArchiveFactory_.get());
+        const StringVector& groups = ResourceGroupManager::getSingleton().getResourceGroups();
+        // Travers all groups
+        for (StringVector::const_iterator itGroup = groups.begin(); itGroup != groups.end(); ++itGroup)
+        {
+            FileInfoListPtr files = ResourceGroupManager::getSingleton().findResourceFileInfo(*itGroup, "*.particle");
+            for (FileInfoList::const_iterator itFile = files->begin(); itFile != files->end(); ++itFile)
+            {
+                // open file
+                Ogre::DataStreamPtr input = ResourceGroupManager::getSingleton().openResource(itFile->filename, *itGroup, false);
+                std::stringstream output;
+                // Parse file and replace "particle_system" with nothing
+                while (!input->eof())
+                {
+                    std::string line = input->getLine();
+                    size_t pos = line.find("particle_system");
+                    if (pos != std::string::npos)
+                    {
+                        // 15 is the length of "particle_system"
+                        line.replace(pos, 15, "");
+                    }
+                    output << line << std::endl;
+                }
+                // Add file to the memory archive
+                shared_array<char> data(new char[output.str().size()]);
+                // Debug optimisations
+                const std::string outputStr = output.str();
+                char* rawData = data.get();
+                for (unsigned i = 0; i < outputStr.size(); ++i)
+                    rawData[i] = outputStr[i];
+                MemoryArchive::addFile("particle_scripts_ogre_1.4_" + *itGroup, itFile->filename, data, output.str().size());
+            }
+            if (!files->empty())
+            {
+                // Declare the files, but using a new group
+                ResourceGroupManager::getSingleton().addResourceLocation("particle_scripts_ogre_1.4_" + *itGroup,
+                    "Memory", "particle_scripts_ogre_1.4_" + *itGroup);
+            }
+        }
+#endif
+
+        // Initialise all resources (do this AFTER the renderer has been loaded!)
+        // Note: You can only do this once! Ogre will check whether a resource group has
+        // already been initialised. If you need to load resources later, you will have to
+        // choose another resource group.
+        Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
+    }
+
+    /**
+    @brief
+        Creates the Ogre Root object and sets up the ogre log.
+    */
+    void GraphicsManager::loadOgreRoot()
+    {
+        COUT(3) << "Setting up Ogre..." << std::endl;
+
+        if (ogreConfigFile_ == "")
+        {
+            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
+            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
+        }
+        if (ogreLogFile_ == "")
+        {
+            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
+            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
+        }
+
+        boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
+        boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
+
+        // create a new logManager
+        // Ogre::Root will detect that we've already created a Log
+        ogreLogger_.reset(new Ogre::LogManager());
+        COUT(4) << "Ogre LogManager created" << std::endl;
+
+        // create our own log that we can listen to
+        Ogre::Log *myLog;
+        myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
+        COUT(4) << "Ogre Log created" << std::endl;
+
+        myLog->setLogDetail(Ogre::LL_BOREME);
+        myLog->addListener(this);
+
+        COUT(4) << "Creating Ogre Root..." << std::endl;
+
+        // check for config file existence because Ogre displays (caught) exceptions if not
+        if (!boost::filesystem::exists(ogreConfigFilepath))
+        {
+            // create a zero sized file
+            std::ofstream creator;
+            creator.open(ogreConfigFilepath.string().c_str());
+            creator.close();
+        }
+
+        // Leave plugins file empty. We're going to do that part manually later
+        ogreRoot_.reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()));
+
+        COUT(3) << "Ogre set up done." << std::endl;
+    }
+
+    void GraphicsManager::loadOgrePlugins()
+    {
+        // just to make sure the next statement doesn't segfault
+        if (ogrePluginsDirectory_ == "")
+            ogrePluginsDirectory_ = ".";
+
+        boost::filesystem::path folder(ogrePluginsDirectory_);
+        // Do some SubString magic to get the comma separated list of plugins
+        SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '(', ')', false, '\0');
+        // Use backslash paths on Windows! file_string() already does that though.
+        for (unsigned int i = 0; i < plugins.size(); ++i)
+            ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
+    }
+
+    void GraphicsManager::loadRenderer()
+    {
+        CCOUT(4) << "Configuring Renderer" << std::endl;
+
+        if (!ogreRoot_->restoreConfig())
+            if (!ogreRoot_->showConfigDialog())
+                ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue failed.");
+
+        CCOUT(4) << "Creating render window" << std::endl;
+
+        this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
+        // Propagate the size of the new winodw
+        this->ogreWindowEventListener_->windowResized(renderWindow_);
+
+        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_.get());
+
+        // create a full screen default viewport
+        // Note: This may throw when adding a viewport with an existing z-order!
+        //       But in our case we only have one viewport for now anyway, therefore
+        //       no ScopeGuards or anything to handle exceptions.
+        this->viewport_ = this->renderWindow_->addViewport(0, 0);
+
+        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
+
+        // add console commands
+        FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
+        ccPrintScreen_ = createConsoleCommand(functor1->setObject(this), "printScreen");
+        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
+    }
+
     void GraphicsManager::update(const Clock& time)
     {
@@ -207,165 +352,4 @@
     {
         this->viewport_->setCamera(camera);
-    }
-
-    /**
-    @brief
-        Creates the Ogre Root object and sets up the ogre log.
-    */
-    void GraphicsManager::setupOgre()
-    {
-        COUT(3) << "Setting up Ogre..." << std::endl;
-
-        if (ogreConfigFile_ == "")
-        {
-            COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
-            ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
-        }
-        if (ogreLogFile_ == "")
-        {
-            COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
-            ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
-        }
-
-        boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
-        boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
-
-        // create a new logManager
-        // Ogre::Root will detect that we've already created a Log
-        std::auto_ptr<Ogre::LogManager> logger(new Ogre::LogManager());
-        COUT(4) << "Ogre LogManager created" << std::endl;
-
-        // create our own log that we can listen to
-        Ogre::Log *myLog;
-        myLog = logger->createLog(ogreLogFilepath.string(), true, false, false);
-        COUT(4) << "Ogre Log created" << std::endl;
-
-        myLog->setLogDetail(Ogre::LL_BOREME);
-        myLog->addListener(this);
-
-        COUT(4) << "Creating Ogre Root..." << std::endl;
-
-        // check for config file existence because Ogre displays (caught) exceptions if not
-        if (!boost::filesystem::exists(ogreConfigFilepath))
-        {
-            // create a zero sized file
-            std::ofstream creator;
-            creator.open(ogreConfigFilepath.string().c_str());
-            creator.close();
-        }
-
-        // Leave plugins file empty. We're going to do that part manually later
-        ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
-        // In case that new Root failed the logger gets destroyed because of the std::auto_ptr
-        ogreLogger_ = logger.release();
-
-        COUT(3) << "Ogre set up done." << std::endl;
-    }
-
-    void GraphicsManager::loadOgrePlugins()
-    {
-        // just to make sure the next statement doesn't segfault
-        if (ogrePluginsFolder_ == "")
-            ogrePluginsFolder_ = ".";
-
-        boost::filesystem::path folder(ogrePluginsFolder_);
-        // Do some SubString magic to get the comma separated list of plugins
-        SubString plugins(ogrePlugins_, ",", " ", false, '\\', false, '"', false, '(', ')', false, '\0');
-        // Use backslash paths on Windows! file_string() already does that though.
-        for (unsigned int i = 0; i < plugins.size(); ++i)
-            ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
-    }
-
-    void GraphicsManager::declareResources()
-    {
-        CCOUT(4) << "Declaring Resources" << std::endl;
-        //TODO: Specify layout of data file and maybe use xml-loader
-        //TODO: Work with ressource groups (should be generated by a special loader)
-
-        if (resourceFile_ == "")
-        {
-            COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
-            ModifyConfigValue(resourceFile_, tset, "resources.cfg");
-        }
-
-        // Load resource paths from data file using configfile ressource type
-        Ogre::ConfigFile cf;
-        try
-        {
-            cf.load((Core::getMediaPath() / resourceFile_).string());
-        }
-        catch (...)
-        {
-            //COUT(1) << ex.getFullDescription() << std::endl;
-            COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
-            throw;
-        }
-
-        // Go through all sections & settings in the file
-        Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
-
-        std::string secName, typeName, archName;
-        while (seci.hasMoreElements())
-        {
-            try
-            {
-                secName = seci.peekNextKey();
-                Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
-                Ogre::ConfigFile::SettingsMultiMap::iterator i;
-                for (i = settings->begin(); i != settings->end(); ++i)
-                {
-                    typeName = i->first; // for instance "FileSystem" or "Zip"
-                    archName = i->second; // name (and location) of archive
-
-                    Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
-                        (Core::getMediaPath() / archName).string(), typeName, secName);
-                }
-            }
-            catch (Ogre::Exception& ex)
-            {
-                COUT(1) << ex.getFullDescription() << std::endl;
-            }
-        }
-    }
-
-    void GraphicsManager::loadRenderer()
-    {
-        CCOUT(4) << "Configuring Renderer" << std::endl;
-
-        if (!ogreRoot_->restoreConfig())
-            if (!ogreRoot_->showConfigDialog())
-                ThrowException(InitialisationFailed, "OGRE graphics configuration dialogue failed.");
-
-        CCOUT(4) << "Creating render window" << std::endl;
-
-        this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
-        this->ogreWindowEventListener_->windowResized(renderWindow_);
-
-        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
-
-        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
-
-        // create a full screen default viewport
-        this->viewport_ = this->renderWindow_->addViewport(0, 0);
-    }
-
-    void GraphicsManager::initialiseResources()
-    {
-        CCOUT(4) << "Initialising resources" << std::endl;
-        //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
-        //try
-        //{
-            Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
-            /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
-            for (unsigned int i = 0; i < str.size(); i++)
-            {
-            Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
-            }*/
-        //}
-        //catch (...)
-        //{
-        //    CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
-        //    throw;
-        //}
     }
 
@@ -406,4 +390,28 @@
     }
 
+    size_t GraphicsManager::getRenderWindowHandle()
+    {
+        size_t windowHnd = 0;
+        renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
+        return windowHnd;
+    }
+
+    bool GraphicsManager::isFullScreen() const
+    {
+        Ogre::ConfigOptionMap& options = ogreRoot_->getRenderSystem()->getConfigOptions();
+        if (options.find("Full Screen") != options.end())
+        {
+            if (options["Full Screen"].currentValue == "Yes")
+                return true;
+            else
+                return false;
+        }
+        else
+        {
+            COUT(0) << "Could not find 'Full Screen' render system option. Fix This!!!" << std::endl;
+            return false;
+        }
+    }
+
     void GraphicsManager::printScreen()
     {
Index: code/trunk/src/core/GraphicsManager.h
===================================================================
--- code/trunk/src/core/GraphicsManager.h	(revision 5693)
+++ code/trunk/src/core/GraphicsManager.h	(revision 5695)
@@ -42,4 +42,7 @@
 #include <string>
 #include <OgreLog.h>
+#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
+
 #include "util/Singleton.h"
 #include "OrxonoxClass.h"
@@ -55,5 +58,5 @@
         friend class Singleton<GraphicsManager>;
     public:
-        GraphicsManager();
+        GraphicsManager(bool bLoadRenderer = true);
         ~GraphicsManager();
 
@@ -62,8 +65,11 @@
         void update(const Clock& time);
 
-        inline Ogre::Viewport* getViewport()
-            { return this->viewport_; }
-        inline Ogre::RenderWindow* getRenderWindow()
-            { return this->renderWindow_; }
+        Ogre::Viewport* getViewport()         { return this->viewport_; }
+        Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
+        size_t getRenderWindowHandle();
+        bool isFullScreen() const;
+
+        void upgradeToGraphics();
+        bool rendererLoaded() const { return renderWindow_ != NULL; }
 
         void setCamera(Ogre::Camera* camera);
@@ -73,9 +79,7 @@
 
         // OGRE initialisation
-        void setupOgre();
+        void loadOgreRoot();
         void loadOgrePlugins();
-        void declareResources();
         void loadRenderer();
-        void initialiseResources();
 
         // event from Ogre::LogListener
@@ -86,15 +90,20 @@
         void printScreen();
 
-    private:
-        Ogre::Root*         ogreRoot_;                 //!< Ogre's root
-        Ogre::LogManager*   ogreLogger_;
+        scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
+#if OGRE_VERSION < 0x010600
+        scoped_ptr<MemoryArchiveFactory>    memoryArchiveFactory_;    //!< Stores the modified particle scripts
+#endif
+        scoped_ptr<Ogre::LogManager>        ogreLogger_;
+        scoped_ptr<Ogre::Root>              ogreRoot_;                //!< Ogre's root
         Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
         Ogre::Viewport*     viewport_;                 //!< default full size viewport
-        OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
+
+        // XML files for the resources
+        shared_ptr<XMLFile> resources_;                //!< XML with resource locations
+        shared_ptr<XMLFile> extResources_;             //!< XML with resource locations in the external path (only for dev runs)
 
         // config values
-        std::string         resourceFile_;             //!< resources file name
         std::string         ogreConfigFile_;           //!< ogre config file name
-        std::string         ogrePluginsFolder_;        //!< Folder where the Ogre plugins are located
+        std::string         ogrePluginsDirectory_;     //!< Directory where the Ogre plugins are located
         std::string         ogrePlugins_;              //!< Comma separated list of all plugins to load
         std::string         ogreLogFile_;              //!< log file name for Ogre log messages
Index: code/trunk/src/core/Identifier.cc
===================================================================
--- code/trunk/src/core/Identifier.cc	(revision 5693)
+++ code/trunk/src/core/Identifier.cc	(revision 5695)
@@ -138,5 +138,5 @@
         if (!this->bCreatedOneObject_ && Identifier::isCreatingHierarchy())
         {
-            // If no: We have to store the informations and initialize the Identifier
+            // If no: We have to store the information and initialize the Identifier
             COUT(4) << "*** ClassIdentifier: Register Class in " << this->getName() << "-Singleton -> Initialize Singleton." << std::endl;
             if (bRootClass)
Index: code/trunk/src/core/Identifier.h
===================================================================
--- code/trunk/src/core/Identifier.h	(revision 5693)
+++ code/trunk/src/core/Identifier.h	(revision 5695)
@@ -31,5 +31,5 @@
     @brief Definition of the Identifier, ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.
 
-    The Identifier contains all needed informations about the class it belongs to:
+    The Identifier contains all needed information about the class it belongs to:
      - the name
      - a list with all objects
@@ -73,7 +73,7 @@
     // ###       Identifier        ###
     // ###############################
-    //! The Identifier is used to identify the class of an object and to store informations about the class.
-    /**
-        The Identifier contains all needed informations about the class it belongs to:
+    //! The Identifier is used to identify the class of an object and to store information about the class.
+    /**
+        The Identifier contains all needed information about the class it belongs to:
          - the name
          - a list with all objects
@@ -335,5 +335,5 @@
     /**
         ClassIdentifier is a Singleton, which means that only one object of a given type T exists.
-        This makes it possible to store informations about a class, sharing them with all
+        This makes it possible to store information about a class, sharing them with all
         objects of that class without defining static variables in every class.
 
Index: code/trunk/src/core/Loader.cc
===================================================================
--- code/trunk/src/core/Loader.cc	(revision 5693)
+++ code/trunk/src/core/Loader.cc	(revision 5695)
@@ -29,13 +29,17 @@
 #include "Loader.h"
 
+#include <sstream>
 #include <tinyxml/ticpp.h>
+#include <boost/scoped_ptr.hpp>
 
 #include "util/Debug.h"
 #include "util/Exception.h"
+#include "util/StringUtils.h"
 #include "BaseObject.h"
 #include "Iterator.h"
 #include "ObjectList.h"
-#include "LuaBind.h"
+#include "LuaState.h"
 #include "Namespace.h"
+#include "Resource.h"
 #include "XMLFile.h"
 
@@ -118,9 +122,23 @@
         Loader::currentMask_s = file->getMask() * mask;
 
-        // let Lua work this out:
-        LuaBind& lua = LuaBind::getInstance();
-        lua.clearLuaOutput();
-        lua.loadFile(file->getFilename(), true);
-        lua.run();
+        std::string xmlInput;
+        if (file->getLuaSupport())
+        {
+            // Use the LuaState to replace the XML tags (calls our function)
+            scoped_ptr<LuaState> luaState(new LuaState());
+            luaState->setIncludeParser(&Loader::replaceLuaTags);
+            luaState->includeFile(file->getFilename(), file->getResourceGroup(), false);
+            xmlInput = luaState->getOutput().str();
+        }
+        else
+        {
+            shared_ptr<ResourceInfo> info = Resource::getInfo(file->getFilename(), file->getResourceGroup());
+            if (info == NULL)
+            {
+                COUT(1) << "Error: Could not find XML file '" << file->getFilename() << "'." << std::endl;
+                return false;
+            }
+            xmlInput = Resource::open(file->getFilename(), file->getResourceGroup())->getAsString();
+        }
 
         try
@@ -129,10 +147,6 @@
             COUT(3) << "Mask: " << Loader::currentMask_s << std::endl;
 
-            //ticpp::Document xmlfile(file->getFilename());
-            //xmlfile.LoadFile();
-            //ticpp::Element myelement(*Script::getFileString());
-            ticpp::Document xmlfile;
-            //xmlfile.ToDocument();
-            xmlfile.Parse(lua.getLuaOutput(), true);
+            ticpp::Document xmlfile(file->getFilename());
+            xmlfile.Parse(xmlInput, true);
 
             ticpp::Element rootElement;
@@ -208,3 +222,154 @@
         return Loader::load(file, mask);
     }
+
+    std::string Loader::replaceLuaTags(const std::string& text)
+    {
+        // chreate map with all Lua tags
+        std::map<size_t, bool> luaTags;
+        {
+            size_t pos = 0;
+            while ((pos = text.find("<?lua", pos)) != std::string::npos)
+                luaTags[pos++] = true;
+        }
+        {
+            size_t pos = 0;
+            while ((pos = text.find("?>", pos)) != std::string::npos)
+                luaTags[pos++] = false;
+        }
+
+        // erase all tags from the map that are between two quotes
+        {
+            std::map<size_t, bool>::iterator it = luaTags.begin();
+            std::map<size_t, bool>::iterator it2 = it;
+            bool bBetweenQuotes = false;
+            size_t pos = 0;
+            while ((pos = getNextQuote(text, pos)) != std::string::npos)
+            {
+                while ((it != luaTags.end()) && (it->first < pos))
+                {
+                    if (bBetweenQuotes)
+                    {
+                        it2++;
+                        if(it->second && !(it2->second) && it2->first < pos)
+                            it = ++it2;
+                        else
+                            luaTags.erase(it++);
+                    }
+                    else
+                        ++it;
+                }
+                bBetweenQuotes = !bBetweenQuotes;
+                pos++;
+            }
+        }
+
+        // check whether on every opening <?lua tag a closing ?> tag follows
+        {
+            bool expectedValue = true;
+            for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
+            {
+                if (it->second == expectedValue)
+                    expectedValue = !expectedValue;
+                else
+                {
+                    expectedValue = false;
+                    break;
+                }
+            }
+            if (!expectedValue)
+            {
+                COUT(2) << "Warning: Error in level file" << std::endl;
+                // todo: errorhandling
+                return "";
+            }
+        }
+
+        // Use a stringstream object to speed up the parsing
+        std::ostringstream output;
+
+        // cut the original string into pieces and put them together with print() instead of lua tags
+        {
+            std::map<size_t, bool>::iterator it = luaTags.begin();
+            bool bInPrintFunction = true;
+            size_t start = 0;
+            size_t end = 0;
+
+            do
+            {
+                if (it != luaTags.end())
+                    end = (*(it++)).first;
+                else
+                    end = std::string::npos;
+
+                unsigned int equalSignCounter = 0;
+
+                if (bInPrintFunction)
+                {
+                    // count ['='[ and ]'='] and replace tags with print([[ and ]])
+                    std::string temp = text.substr(start, end - start);
+                    {
+                    size_t pos = 0;
+                    while ((pos = temp.find('[', pos)) != std::string::npos)
+                    {
+                        unsigned int tempCounter = 1;
+                        size_t tempPos = pos++;
+                        while(temp[++tempPos] == '=')
+                        {
+                            tempCounter++;
+                        }
+                        if(temp[tempPos] != '[')
+                        {
+                            tempCounter = 0;
+                        }
+                        else if(tempCounter == 0)
+                        {
+                            tempCounter = 1;
+                        }
+                        if (tempCounter > equalSignCounter)
+                            equalSignCounter = tempCounter;
+                        }
+                    }
+                    {
+                        size_t pos = 0;
+                        while ((pos = temp.find(']', pos)) != std::string::npos)
+                        {
+                            unsigned int tempCounter = 1;
+                            size_t tempPos = pos++;
+                            while(temp[++tempPos] == '=')
+                            {
+                                tempCounter++;
+                            }
+                            if(temp[tempPos] != ']')
+                            {
+                                tempCounter = 0;
+                            }
+                            else if(tempCounter == 0)
+                            {
+                                tempCounter = 1;
+                            }
+                            if (tempCounter > equalSignCounter)
+                                equalSignCounter = tempCounter;
+                        }
+                    }
+                    std::string equalSigns = "";
+                    for(unsigned int i = 0; i < equalSignCounter; i++)
+                    {
+                        equalSigns += "=";
+                    }
+                    output << "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
+                    start = end + 5;
+                }
+                else
+                {
+                    output << text.substr(start, end - start);
+                    start = end + 2;
+                }
+
+                bInPrintFunction = !bInPrintFunction;
+            }
+            while (end != std::string::npos);
+        }
+
+        return output.str();
+    }
 }
Index: code/trunk/src/core/Loader.h
===================================================================
--- code/trunk/src/core/Loader.h	(revision 5693)
+++ code/trunk/src/core/Loader.h	(revision 5695)
@@ -55,4 +55,6 @@
             static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask());
 
+            static std::string replaceLuaTags(const std::string& text);
+
             static ClassTreeMask currentMask_s;
 
Index: code/trunk/src/core/LuaBind.cc
===================================================================
--- code/trunk/src/core/LuaBind.cc	(revision 5693)
+++ 	(revision )
@@ -1,343 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Benjamin Knecht
- *   Co-authors:
- *      ...
- *
- */
-
-#include "LuaBind.h"
-
-#include <fstream>
-#include <map>
-extern "C" {
-#include <lualib.h>
-}
-#include <tolua/tolua++.h>
-#include <boost/filesystem.hpp>
-
-#include "util/Debug.h"
-#include "util/StringUtils.h"
-#include "Core.h"
-
-namespace orxonox
-{
-  LuaBind* LuaBind::singletonPtr_s = NULL;
-
-  LuaBind::LuaBind()
-  {
-    this->includePath_ = Core::getMediaPathString();
-
-    luaState_ = lua_open();
-    luaSource_ = "";
-#if LUA_VERSION_NUM == 501
-    luaL_openlibs(luaState_);
-#else
-    luaopen_base(luaState_);
-    luaopen_string(luaState_);
-    luaopen_table(luaState_);
-    luaopen_math(luaState_);
-    luaopen_io(luaState_);
-    luaopen_debug(luaState_);
-#endif
-
-    // Open all available tolua interfaces
-    this->openToluaInterfaces(luaState_);
-
-    output_ = "";
-    isRunning_ = false;
-  }
-
-  LuaBind::~LuaBind()
-  {
-    this->closeToluaInterfaces(luaState_);
-  };
-
-  void LuaBind::luaPrint(const std::string& str)
-  {
-    output_ += str;
-//    COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
-    COUT(5) << str;
-  }
-
-  /**
-      @brief Loads the specified file line by line
-      @param filename The filename of the file
-      @param luaTags if true, the loaded file gets stripped off luaTags
-  */
-  void LuaBind::loadFile(const std::string& filename, bool luaTags)
-  {
-    boost::filesystem::path filepath(filename);
-
-    output_ = "";
-    std::ifstream file;
-    file.open(filepath.string().c_str(), std::fstream::in);
-
-    if (!file.is_open())
-    {
-      // some error msg
-    }
-
-    std::string levelString = "";
-
-    while (file.good() && !file.eof())
-    {
-      std::string line;
-      std::getline(file, line);
-      levelString += line;
-      levelString += "\n";
-    }
-
-    file.close();
-    //std::string output;
-
-    if (luaTags)
-      luaSource_ = replaceLuaTags(levelString);
-    else
-      luaSource_ = levelString;
-    COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl;
-  }
-
-  void LuaBind::loadString(const std::string& code)
-  {
-    luaSource_ = code;
-    output_ = "";
-  }
-
-#if LUA_VERSION_NUM != 501
-  const char * LuaBind::lua_Chunkreader(lua_State *L, void *data, size_t *size)
-  {
-    LoadS* ls = static_cast<LoadS*>(data);
-    if (ls->size == 0) return NULL;
-    *size = ls->size;
-    ls->size = 0;
-    return ls->s;
-  }
-#endif
-  void LuaBind::run()
-  {
-    if (!isRunning_)
-    {
-      isRunning_ = true;
-      int error = 0;
-      std::string init =
-         "local scr = orxonox.LuaBind:getInstance()\n \
-          local debug = print\n \
-          print = function(s)\n \
-              scr:luaPrint(s)\n \
-          end\n \
-          include = function(f)\n \
-              file = assert(io.open(\"" + this->includePath_ + "\"..\"/\"..f))\n \
-              content = file:read(\"*a\")\n \
-              file:close()\n \
-              source = scr:replaceLuaTags(content)\n \
-              assert(loadstring(source))()\n \
-          end\n";
-      init += luaSource_;
-  #if LUA_VERSION_NUM == 501
-      error = luaL_loadstring(luaState_, init.c_str());
-  #else
-      LoadS ls;
-      ls.s = init.c_str();
-      ls.size = init.size();
-      error = lua_load(luaState_, &orxonox::LuaBind::lua_Chunkreader, &ls, init.c_str());
-  #endif
-      if (error == 0)
-      {
-        error = lua_pcall(luaState_, 0, 0, 0);
-      }
-      if (error != 0)
-      {
-        COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
-      }
-      isRunning_ = false;
-    }
-    else
-    {
-      COUT(2) << "Warning: Lua's run is called while running!" << std::endl;
-    }
-  }
-
-  std::string LuaBind::replaceLuaTags(const std::string& text)
-  {
-    // chreate map with all Lua tags
-    std::map<size_t, bool> luaTags;
-    {
-      size_t pos = 0;
-      while ((pos = text.find("<?lua", pos)) != std::string::npos)
-        luaTags[pos++] = true;
-    }
-    {
-      size_t pos = 0;
-      while ((pos = text.find("?>", pos)) != std::string::npos)
-        luaTags[pos++] = false;
-    }
-
-    // erase all tags from the map that are between two quotes
-    {
-      std::map<size_t, bool>::iterator it = luaTags.begin();
-      std::map<size_t, bool>::iterator it2 = it;
-      bool bBetweenQuotes = false;
-      size_t pos = 0;
-      while ((pos = getNextQuote(text, pos)) != std::string::npos)
-      {
-        while ((it != luaTags.end()) && (it->first < pos))
-        {
-          if (bBetweenQuotes) {
-            it2++;
-            if(it->second && !(it2->second) && it2->first < pos)
-              it = ++it2;
-            else
-              luaTags.erase(it++);
-          }
-          else
-            ++it;
-        }
-        bBetweenQuotes = !bBetweenQuotes;
-        pos++;
-      }
-    }
-
-    // check whether on every opening <?lua tag a closing ?> tag follows
-    {
-      bool expectedValue = true;
-      for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
-      {
-        if (it->second == expectedValue)
-          expectedValue = !expectedValue;
-        else
-        {
-          expectedValue = false;
-          break;
-        }
-      }
-      if (!expectedValue) {
-        COUT(2) << "Warning: Error in level file" << std::endl;
-        // todo: errorhandling
-        return "";
-      }
-    }
-
-    // cut the original string into pieces and put them together with print() instead of lua tags
-    std::string output;
-    {
-      std::map<size_t, bool>::iterator it = luaTags.begin();
-      bool bInPrintFunction = true;
-      size_t start = 0;
-      size_t end = 0;
-
-      do
-      {
-        if (it != luaTags.end())
-          end = (*(it++)).first;
-        else
-          end = std::string::npos;
-
-        unsigned int equalSignCounter = 0;
-
-        if (bInPrintFunction)
-        {
-          // count ['='[ and ]'='] and replace tags with print([[ and ]])
-          std::string temp = text.substr(start, end - start);
-          {
-            size_t pos = 0;
-            while ((pos = temp.find('[', pos)) != std::string::npos)
-            {
-              unsigned int tempCounter = 1;
-              size_t tempPos = pos++;
-              while(temp[++tempPos] == '=') {
-                tempCounter++;
-              }
-              if(temp[tempPos] != '[') {
-                tempCounter = 0;
-              }
-              else if(tempCounter == 0) {
-                tempCounter = 1;
-              }
-              if (tempCounter > equalSignCounter)
-                equalSignCounter = tempCounter;
-            }
-          }
-          {
-            size_t pos = 0;
-            while ((pos = temp.find(']', pos)) != std::string::npos)
-            {
-              unsigned int tempCounter = 1;
-              size_t tempPos = pos++;
-              while(temp[++tempPos] == '=') {
-                tempCounter++;
-              }
-              if(temp[tempPos] != ']') {
-                tempCounter = 0;
-              }
-              else if(tempCounter == 0) {
-                tempCounter = 1;
-              }
-              if (tempCounter > equalSignCounter)
-                equalSignCounter = tempCounter;
-            }
-          }
-          std::string equalSigns = "";
-          for(unsigned int i = 0; i < equalSignCounter; i++) {
-            equalSigns += "=";
-          }
-          output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
-          start = end + 5;
-        }
-        else
-        {
-          output += text.substr(start, end - start);
-          start = end + 2;
-        }
-
-        bInPrintFunction = !bInPrintFunction;
-      }
-      while (end != std::string::npos);
-    }
-
-    return output;
-  }
-
-  void LuaBind::addToluaInterface(int (*function)(lua_State*), const std::string& name)
-  {
-    toluaInterfaces_.push_back(std::make_pair(name, function));
-    // Apply changes to our own lua state as well 
-    (*function)(luaState_);
-  }
-
-  void LuaBind::openToluaInterfaces(lua_State* state)
-  {
-    for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i)
-      (*toluaInterfaces_[i].second)(state);
-  }
-
-  void LuaBind::closeToluaInterfaces(lua_State* state)
-  {
-    for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i)
-    {
-      lua_pushnil(state);
-      lua_setglobal(state, toluaInterfaces_[i].first.c_str());
-    }
-  }
-
-}
Index: code/trunk/src/core/LuaBind.h
===================================================================
--- code/trunk/src/core/LuaBind.h	(revision 5693)
+++ 	(revision )
@@ -1,105 +1,0 @@
-/*
- *   ORXONOX - the hottest 3D action shooter ever to exist
- *                    > www.orxonox.net <
- *
- *
- *   License notice:
- *
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version 2
- *   of the License, or (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- *   Author:
- *      Benjamin Knecht
- *   Co-authors:
- *      ...
- *
- */
-
-/**
- @file
- @brief Representation of an interface to lua
- @author Benjamin Knecht <beni_at_orxonox.net>
- */
-
-#ifndef _LuaBind_H__
-#define _LuaBind_H__
-
-#include "CorePrereqs.h"
-
-#include <cassert>
-#include <string>
-#include <vector>
-extern "C" {
-#include <lua.h>
-}
-
-#include "util/Singleton.h"
-
-// tolua_begin
-namespace orxonox
-{
-  class _CoreExport LuaBind : public Singleton<LuaBind>
-  {
-// tolua_end
-    friend class Singleton<LuaBind>;
-
-    struct LoadS {
-      const char *s;
-      size_t size;
-    };
-
-    public:
-      LuaBind();
-      ~LuaBind();
-
-      static LuaBind& getInstance() { return Singleton<LuaBind>::getInstance(); } // tolua_export
-
-    void loadFile(const std::string& filename, bool luaTags);
-    void loadString(const std::string& code);
-    //void init(lua_State *state_);
-    //void xmlToLua();
-    void run();
-    void luaPrint(const std::string& str); // tolua_export
-
-#if LUA_VERSION_NUM != 501
-    static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
-#endif
-
-    inline lua_State* getLuaState() { return luaState_; };
-    inline const std::string& getLuaOutput() { return output_; };
-    //inline std::string* getFileString() { return &fileString_; };
-    inline void clearLuaOutput() { output_ = ""; }
-
-    std::string replaceLuaTags(const std::string& text); // tolua_export
-
-    inline void setIncludePath(const std::string& includepath)
-        { this->includePath_ = includepath; }
-
-    void addToluaInterface(int (*function)(lua_State*), const std::string& name);
-    void openToluaInterfaces(lua_State* state);
-    void closeToluaInterfaces(lua_State* state);
-
-    private:
-      static LuaBind* singletonPtr_s;
-
-      std::string luaSource_;
-      std::string output_;
-      lua_State* luaState_;
-      bool isRunning_;
-      std::string includePath_;
-      std::vector<std::pair<std::string, int (*)(lua_State *L)> > toluaInterfaces_;
-
-  }; // tolua_export
-} // tolua_export
-#endif /* _LuaBind_H__ */
Index: code/trunk/src/core/LuaState.cc
===================================================================
--- code/trunk/src/core/LuaState.cc	(revision 5695)
+++ code/trunk/src/core/LuaState.cc	(revision 5695)
@@ -0,0 +1,266 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Benjamin Knecht
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "LuaState.h"
+
+#include <tolua/tolua++.h>
+extern "C" {
+#include <lua.h>
+#include <lualib.h>
+}
+
+#include "util/Debug.h"
+#include "Core.h"
+#include "Resource.h"
+#include "ToluaBindCore.h"
+
+namespace orxonox
+{
+    LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s;
+    std::vector<LuaState*> LuaState::instances_s;
+
+    // Do this after declaring toluaInterfaces_s and instances_s to avoid larger problems
+    DeclareToluaInterface(Core);
+
+    LuaState::LuaState()
+        : bIsRunning_(false)
+        , includeParseFunction_(NULL)
+    {
+        // Create new lua state and configure it
+        luaState_ = lua_open();
+#if LUA_VERSION_NUM == 501
+        luaL_openlibs(luaState_);
+#else
+        luaopen_base(luaState_);
+        luaopen_string(luaState_);
+        luaopen_table(luaState_);
+        luaopen_math(luaState_);
+        luaopen_io(luaState_);
+        luaopen_debug(luaState_);
+#endif
+
+        // Open all available tolua interfaces
+        this->openToluaInterfaces(luaState_);
+
+        // Create dummy file info
+        sourceFileInfo_.reset(new ResourceInfo());
+        sourceFileInfo_->group = "General";
+        sourceFileInfo_->size = 0;
+
+        // Push this pointer
+        tolua_pushusertype(luaState_, static_cast<void*>(this), "orxonox::LuaState");
+        lua_setglobal(luaState_, "luaState");
+
+        // Parse init script
+        this->doFile("LuaStateInit.lua");
+    }
+
+    LuaState::~LuaState()
+    {
+        lua_close(luaState_);
+    }
+
+    shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    {
+        shared_ptr<ResourceInfo> sourceInfo;
+        if (resourceGroup != "NoResourceGroupProvided")
+            sourceInfo = Resource::getInfo(filename, resourceGroup);
+
+        // Continue search if not explicitely forbidden
+        if (bSearchOtherPaths && sourceInfo == NULL)
+        {
+            // Call might be relative to the file currently being processed
+            sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group);
+            if (sourceInfo == NULL)
+            {
+                // Maybe find something in the same group but in the root path
+                sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);
+            }
+        }
+        return sourceInfo;
+    }
+
+    void LuaState::includeFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    {
+        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+        if (sourceInfo != NULL)
+            this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
+        else
+            COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '"
+                    << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
+    }
+
+    void LuaState::includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo)
+    {
+        // Parse string with provided include parser (otherwise don't preparse at all)
+        std::string luaInput;
+        if (includeParseFunction_ != NULL)
+            luaInput = (*includeParseFunction_)(code);
+        else
+            luaInput = code;
+
+        this->doString(luaInput, sourceFileInfo);
+    }
+
+    void LuaState::doFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    {
+        shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+        if (sourceInfo != NULL)
+            this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
+        else
+            COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '"
+                << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
+    }
+
+    void LuaState::doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo)
+    {
+        // Save the oold source file info
+        shared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_;
+        // Only override if sourceFileInfo provides useful information
+        if (sourceFileInfo != NULL)
+            sourceFileInfo_ = sourceFileInfo;
+
+        int error = 0;
+#if LUA_VERSION_NUM != 501
+        LoadS ls;
+        ls.s = code.c_str();
+        ls.size = code.size();
+        error = lua_load(luaState_, &orxonox::LuaState::lua_Chunkreader, &ls, code.c_str());
+#else
+        error = luaL_loadstring(luaState_, code.c_str());
+#endif
+
+        // execute the chunk
+        if (error == 0)
+            error = lua_pcall(luaState_, 0, 1, 0);
+        if (error != 0)
+        {
+            std::string origin;
+            if (sourceFileInfo != NULL)
+                origin = " originating from " + sourceFileInfo_->filename;
+            COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
+            // return value is nil
+            lua_pushnil(luaState_);
+        }
+        // push return value because it will get lost since the return value of this function is void
+        lua_setglobal(luaState_, "LuaStateReturnValue");
+
+        // Load the old info again
+        sourceFileInfo_ = oldSourceFileInfo;
+    }
+
+    void LuaState::luaPrint(const std::string& str)
+    {
+        output_ << str;
+    }
+
+    void LuaState::luaLog(unsigned int level, const std::string& message)
+    {
+        OutputHandler::getOutStream().setOutputLevel(level) << message << std::endl;
+    }
+
+    bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+    {
+        shared_ptr<ResourceInfo> info =  this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+        if (info == NULL)
+            return false;
+        else
+            return true;
+    }
+
+#if LUA_VERSION_NUM != 501
+    const char * LuaState::lua_Chunkreader(lua_State *L, void *data, size_t *size)
+    {
+        LoadS* ls = static_cast<LoadS*>(data);
+        if (ls->size == 0)
+            return NULL;
+        *size = ls->size;
+        ls->size = 0;
+        return ls->s;
+    }
+#endif
+
+    /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name)
+    {
+        for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+        {
+            if (it->first == name || it->second == function)
+            {
+                COUT(2) << "Warning: Trying to add a Tolua interface with the same name or function." << std::endl;
+                return true;
+            }
+        }
+        toluaInterfaces_s[name] = function;
+
+        // Open interface in all LuaStates
+        for (std::vector<LuaState*>::const_iterator it = instances_s.begin(); it != instances_s.end(); ++it)
+            (*function)((*it)->luaState_);
+
+        // Return dummy bool
+        return true;
+    }
+
+    /*static*/ bool LuaState::removeToluaInterface(const std::string& name)
+    {
+        ToluaInterfaceMap::iterator it = toluaInterfaces_s.find(name);
+        if (it == toluaInterfaces_s.end())
+        {
+            COUT(2) << "Warning: Cannot remove Tolua interface '" << name << "': Not found" << std::endl;
+            return true;
+        }
+
+        // Close interface in all LuaStates
+        for (std::vector<LuaState*>::const_iterator itState = instances_s.begin(); itState != instances_s.end(); ++itState)
+        {
+            lua_pushnil((*itState)->luaState_);
+            lua_setglobal((*itState)->luaState_, it->first.c_str());
+        }
+
+        // Remove entry
+        toluaInterfaces_s.erase(it);
+
+        // Return dummy bool
+        return true;
+    }
+
+    /*static*/ void LuaState::openToluaInterfaces(lua_State* state)
+    {
+        for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+            (*it->second)(state);
+    }
+
+    /*static*/ void LuaState::closeToluaInterfaces(lua_State* state)
+    {
+        for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+        {
+            lua_pushnil(state);
+            lua_setglobal(state, it->first.c_str());
+        }
+    }
+}
Index: code/trunk/src/core/LuaState.h
===================================================================
--- code/trunk/src/core/LuaState.h	(revision 5695)
+++ code/trunk/src/core/LuaState.h	(revision 5695)
@@ -0,0 +1,104 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Benjamin Knecht
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _LuaState_H__
+#define _LuaState_H__
+
+#include "CorePrereqs.h"
+
+#include <map>
+#include <sstream>
+#include <string>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+
+#include "util/ScopeGuard.h"
+#include "ToluaInterface.h"
+
+// tolua_begin
+namespace orxonox
+{
+    /**
+    @brief
+        Representation of an interface to lua
+    */
+    class _CoreExport LuaState
+    {
+// tolua_end
+    public:
+        LuaState();
+        ~LuaState();
+
+        void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
+        void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
+
+        void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
+        void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
+
+        void luaPrint(const std::string& str); // tolua_export
+        void luaLog(unsigned int level, const std::string& message); // tolua_export
+        bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
+
+        const std::stringstream& getOutput() const { return output_; }
+        void clearOutput() { output_.clear(); } // tolua_export
+
+        void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; }
+        lua_State* getInternalLuaState() { return luaState_; }
+
+        static bool addToluaInterface(int (*function)(lua_State*), const std::string& name);
+        static bool removeToluaInterface(const std::string& name);
+        static void openToluaInterfaces(lua_State* state);
+        static void closeToluaInterfaces(lua_State* state);
+
+    private:
+        shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths);
+
+#if LUA_VERSION_NUM != 501
+        struct LoadS
+        {
+            const char* s;
+            size_t size;
+        };
+
+        static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
+#endif
+
+        std::stringstream output_;
+        lua_State* luaState_;
+        bool bIsRunning_;
+        shared_ptr<ResourceInfo> sourceFileInfo_;
+        std::string (*includeParseFunction_)(const std::string&);
+
+        typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
+        static ToluaInterfaceMap toluaInterfaces_s;
+        static std::vector<LuaState*> instances_s;
+    }; // tolua_export
+} // tolua_export
+
+#endif /* _LuaState_H__ */
Index: code/trunk/src/core/MemoryArchive.cc
===================================================================
--- code/trunk/src/core/MemoryArchive.cc	(revision 5695)
+++ code/trunk/src/core/MemoryArchive.cc	(revision 5695)
@@ -0,0 +1,133 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "MemoryArchive.h"
+
+#if OGRE_VERSION < 0x010600
+
+#include <OgreException.h>
+#include <boost/filesystem.hpp>
+
+namespace orxonox
+{
+    using namespace Ogre;
+
+    MemoryArchive::ArchiveMap MemoryArchive::archives_s;
+
+    void MemoryArchive::load()
+    {
+        if (archives_s.find(this->getName()) == archives_s.end())
+            OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR, this->getName() + " - MemoryArchive not found.", "MemoryArchive");
+    }
+
+    DataStreamPtr MemoryArchive::open(const String& filename) const
+    {
+        const FileMap& files = archives_s[this->getName()];
+        FileMap::const_iterator itFile = files.find(filename);
+        if (itFile == files.end())
+            return DataStreamPtr();
+        else
+            return MemoryDataStreamPtr(new MemoryDataStream(itFile->second.first.get(), itFile->second.second));
+    }
+
+    void MemoryArchive::findFiles(const String& pattern, bool bRecursive, 
+        bool bDirs, StringVector* simpleList, FileInfoList* detailList)
+    {
+        const FileMap& files = archives_s[this->getName()];
+
+        for (FileMap::const_iterator it = files.begin(); it != files.end(); ++it)
+        {
+            boost::filesystem::path file = it->first;
+            // Check pattern
+            if (!StringUtil::match(file.string(), pattern, true))
+                continue;
+            if (bDirs)
+                file = file.parent_path();
+            if (file.empty())
+                continue;
+            if (file.has_parent_path() && !bRecursive)
+                continue;
+            if (simpleList)
+                simpleList->push_back(file.string());
+            if (detailList)
+            {
+                FileInfo fi;
+                fi.archive = this;
+                fi.filename = file.string();
+                fi.basename = file.filename();
+                fi.path = file.parent_path().string();
+                fi.compressedSize = it->second.second;
+                fi.uncompressedSize = it->second.second;
+                detailList->push_back(fi);
+            }
+        }
+    }
+    StringVectorPtr MemoryArchive::list(bool recursive, bool dirs)
+    {
+        StringVectorPtr ret(new StringVector());
+        findFiles("*", recursive, dirs, ret.getPointer(), 0);
+        return ret;
+    }
+
+    FileInfoListPtr MemoryArchive::listFileInfo(bool recursive, bool dirs)
+    {
+        FileInfoListPtr ret(new FileInfoList());
+        findFiles("*", recursive, dirs, 0, ret.getPointer());
+        return ret;
+    }
+
+    StringVectorPtr MemoryArchive::find(const String& pattern,
+                                            bool recursive, bool dirs)
+    {
+        StringVectorPtr ret(new StringVector());
+        findFiles(pattern, recursive, dirs, ret.getPointer(), 0);
+        return ret;
+    }
+
+    FileInfoListPtr MemoryArchive::findFileInfo(const String& pattern, 
+        bool recursive, bool dirs)
+    {
+        FileInfoListPtr ret(new FileInfoList());
+        findFiles(pattern, recursive, dirs, 0, ret.getPointer());
+        return ret;
+    }
+
+    bool MemoryArchive::exists(const String& filename)
+	{
+        const FileMap& files = archives_s[this->getName()];
+        return files.find(filename) != files.end();
+	}
+
+    const Ogre::String& MemoryArchiveFactory::getType(void) const
+    {
+        static std::string result("Memory");
+        return result;
+    }
+}
+
+#endif /* OGRE_VERSION < 0x010600 */
Index: code/trunk/src/core/MemoryArchive.h
===================================================================
--- code/trunk/src/core/MemoryArchive.h	(revision 5695)
+++ code/trunk/src/core/MemoryArchive.h	(revision 5695)
@@ -0,0 +1,101 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _MemoryArchive_H__
+#define _MemoryArchive_H__
+
+#include "CorePrereqs.h"
+#include <OgrePrerequisites.h>
+
+#if OGRE_VERSION < 0x010600
+
+#include <map>
+#include <OgreArchive.h>
+#include <OgreArchiveFactory.h>
+#include <boost/shared_array.hpp>
+
+namespace orxonox
+{
+    /**
+    @brief
+        Provides a simple mechanism of 'memory mapped IO', but compatible for Ogre 1.4
+
+        Files are stored as shared_array<char> in a static map with the archive names
+        (imaging the different archives as resource locations). This map then contains
+        yet another map with the actual files.
+        If you want to know why we make such a fuss, contact GraphicsManager::upgradeToGraphics()
+        for more information.
+    */
+    class MemoryArchive : public Ogre::Archive
+    {
+    public:
+        MemoryArchive(const Ogre::String& name, const Ogre::String& archiveType) : Ogre::Archive(name, archiveType) { }
+        ~MemoryArchive() { }
+
+        bool isCaseSensitive(void) const { return true; }
+
+        void load();
+        void unload() { }
+
+        Ogre::DataStreamPtr open(const Ogre::String& filename) const;
+
+        Ogre::StringVectorPtr list(bool recursive = true, bool dirs = false);
+        Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
+
+        Ogre::StringVectorPtr find(const Ogre::String& pattern, bool recursive = true,
+            bool dirs = false);
+        Ogre::FileInfoListPtr findFileInfo(const Ogre::String& pattern, bool recursive = true,
+            bool dirs = false);
+
+        bool exists(const Ogre::String& filename);
+
+        static void addFile(const std::string& archiveName, const std::string& filename, shared_array<char> content, size_t size)
+            { archives_s[archiveName][filename] = std::make_pair(content, size); }
+
+    private:
+        void findFiles(const Ogre::String& pattern, bool bRecursive, 
+            bool bDirs, Ogre::StringVector* simpleList, Ogre::FileInfoList* detailList);
+
+        typedef std::map<std::string, std::pair<shared_array<char>, size_t> > FileMap;
+        typedef std::map<std::string, FileMap> ArchiveMap;
+        static ArchiveMap archives_s;
+    };
+
+    //! Specialisation of ArchiveFactory for MemoryArchive.
+    class _CoreExport MemoryArchiveFactory : public Ogre::ArchiveFactory
+    {
+    public:
+        const Ogre::String& getType(void) const;
+        Ogre::Archive* createInstance(const Ogre::String& name) { return new MemoryArchive(name, "Memory"); }
+        void destroyInstance(Ogre::Archive* arch)               { delete arch; }
+    };
+}
+
+#endif /* OGRE_VERSION < 0x010600 */
+
+#endif /* _MemoryArchive_H__ */
Index: code/trunk/src/core/Resource.cc
===================================================================
--- code/trunk/src/core/Resource.cc	(revision 5695)
+++ code/trunk/src/core/Resource.cc	(revision 5695)
@@ -0,0 +1,69 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "Resource.h"
+#include <OgreResourceGroupManager.h>
+
+namespace orxonox
+{
+    std::string Resource::DEFAULT_GROUP(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+
+    DataStreamPtr Resource::open(const std::string& name, const std::string& group, bool bSearchGroupsIfNotFound)
+    {
+        return Ogre::ResourceGroupManager::getSingleton().openResource(name, group, bSearchGroupsIfNotFound);
+    }
+
+    DataStreamListPtr Resource::openMulti(const std::string& pattern, const std::string& group)
+    {
+        return Ogre::ResourceGroupManager::getSingleton().openResources(pattern, group);
+    }
+
+    bool Resource::exists(const std::string& name, const std::string& group)
+    {
+        return Ogre::ResourceGroupManager::getSingleton().resourceExists(group, name);
+    }
+
+    shared_ptr<ResourceInfo> Resource::getInfo(const std::string& name, const std::string& group)
+    {
+        Ogre::FileInfoListPtr infos = Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(group, name);
+        for (std::vector<Ogre::FileInfo>::const_iterator it = infos->begin(); it != infos->end(); ++it)
+        {
+            if (it->filename == name)
+            {
+                shared_ptr<ResourceInfo> ptr(new ResourceInfo());
+                ptr->filename = name;
+                ptr->path = it->path;
+                ptr->basename = it->basename;
+                ptr->group = group;
+                ptr->size = it->uncompressedSize;
+                return ptr;
+            }
+        }
+        return shared_ptr<ResourceInfo>();
+    }
+}
Index: code/trunk/src/core/Resource.h
===================================================================
--- code/trunk/src/core/Resource.h	(revision 5695)
+++ code/trunk/src/core/Resource.h	(revision 5695)
@@ -0,0 +1,134 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Core_Resource_H__
+#define _Core_Resource_H__
+
+#include "CorePrereqs.h"
+
+#include <boost/shared_ptr.hpp>
+#include <OgreDataStream.h>
+
+namespace orxonox
+{
+    // Import the Ogre::DataStreamList
+    using Ogre::DataStreamList;
+    using Ogre::DataStreamListPtr;
+
+    //! Stores basic information about a Resource from Ogre
+    struct ResourceInfo
+    {
+        //! The file's fully qualified name
+        std::string filename;
+        //! Path name; separated by '/' and ending with '/'
+        std::string path;
+        //! Base filename
+        std::string basename;
+        //! Resource group the file is in
+        std::string group;
+        //! Uncompressed size
+        size_t size;
+    };
+
+    /**
+    @brief
+        Provides simple functions to easily access the Ogre::ResourceGroupManager
+    */
+    class _CoreExport Resource
+    {
+        // Docs by Ogre::ResourceGroupManager.h
+    public:
+		/**
+        @brief
+            Open a single resource by name and return a DataStream
+            pointing at the source of the data.
+        @param name
+            The name of the resource to locate.
+            Even if resource locations are added recursively, you
+            must provide a fully qualified name to this method.
+        @param groupName
+            The name of the resource group; this determines which 
+            locations are searched. 
+        @param searchGroupsIfNotFound
+            If true, if the resource is not found in 
+            the group specified, other groups will be searched.
+        @return
+            Shared pointer to data stream containing the data. Will be
+            destroyed automatically when no longer referenced.
+		*/
+        static DataStreamPtr open(const std::string& name,
+            const std::string& group = Resource::DEFAULT_GROUP,
+            bool bSearchGroupsIfNotFound = false);
+
+		/**
+        @brief
+            Open all resources matching a given pattern (which can contain
+            the character '*' as a wildcard), and return a collection of 
+            DataStream objects on them.
+        @param pattern
+            The pattern to look for. If resource locations have been
+            added recursively, subdirectories will be searched too so this
+            does not need to be fully qualified.
+        @param groupName
+            The resource group; this determines which locations
+            are searched.
+        @return
+            Shared pointer to a data stream list , will be
+            destroyed automatically when no longer referenced
+		*/
+        static DataStreamListPtr openMulti(const std::string& pattern, const std::string& group = Resource::DEFAULT_GROUP);
+
+        /**
+            Find out if the named file exists in a group. 
+        @param filename
+            Fully qualified name of the file to test for
+        @param group
+            The name of the resource group
+        */
+        static bool exists(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
+
+        /**
+            Get struct with information about group, path and size.
+        @param filename
+            Fully qualified name of the file to test for
+        @param group
+            The name of the resource group
+        */
+        static shared_ptr<ResourceInfo> getInfo(const std::string& name, const std::string& group = Resource::DEFAULT_GROUP);
+
+        //! Name of the default resource group (usually "General")
+        static std::string DEFAULT_GROUP;
+
+    private:
+        Resource();
+        ~Resource();
+        Resource(const Resource& instance);
+    };
+}
+
+#endif /* _Core_Resource_H__ */
Index: code/trunk/src/core/TclBind.cc
===================================================================
--- code/trunk/src/core/TclBind.cc	(revision 5693)
+++ code/trunk/src/core/TclBind.cc	(revision 5695)
@@ -127,5 +127,5 @@
 #ifdef DEPENDENCY_PACKAGE_ENABLE
         if (Core::isDevelopmentRun())
-            return (std::string(ORXONOX_DEP_LIB_PATH) + "/tcl");
+            return (std::string(specialConfig::dependencyLibraryDirectory) + "/tcl");
         else
             return (Core::getRootPathString() + "lib/tcl");
Index: code/trunk/src/core/TclThreadManager.cc
===================================================================
--- code/trunk/src/core/TclThreadManager.cc	(revision 5693)
+++ code/trunk/src/core/TclThreadManager.cc	(revision 5695)
@@ -57,5 +57,5 @@
 
     /**
-        @brief A struct containing all informations about a Tcl-interpreter
+        @brief A struct containing all information about a Tcl-interpreter
     */
     struct TclInterpreterBundle
Index: code/trunk/src/core/ToluaInterface.h
===================================================================
--- code/trunk/src/core/ToluaInterface.h	(revision 5695)
+++ code/trunk/src/core/ToluaInterface.h	(revision 5695)
@@ -0,0 +1,45 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+@file
+    This is required because tolua would parse this macro in LuaState.h and fail
+*/
+
+#ifndef _ToluaInterface_H__
+#define _ToluaInterface_H__
+
+#include "CorePrereqs.h"
+#include <boost/preprocessor/cat.hpp>
+
+// Macro for declaring a tolua interface of a library/module
+#define DeclareToluaInterface(libraryName) \
+    static bool BOOST_PP_CAT(bDummy##libraryName, __LINE__) = orxonox::LuaState::addToluaInterface(&tolua_##libraryName##_open, #libraryName); \
+    static Loki::ScopeGuardImpl1<bool (*)(const std::string&), std::string> BOOST_PP_CAT(dummy##libraryName, __LINE__)(&orxonox::LuaState::removeToluaInterface, #libraryName)
+
+#endif /* _ToluaInterface_H__ */
Index: code/trunk/src/core/XMLFile.h
===================================================================
--- code/trunk/src/core/XMLFile.h	(revision 5693)
+++ code/trunk/src/core/XMLFile.h	(revision 5695)
@@ -40,13 +40,28 @@
     {
         public:
-            XMLFile(const std::string& filename) : filename_(filename) {}
-            XMLFile(const std::string& filename, const ClassTreeMask& mask) : filename_(filename), mask_(mask) {};
+            XMLFile(const std::string& filename, const std::string& resourceGroup = "General")
+                : filename_(filename)
+                , group_(resourceGroup)
+                , bLuaSupport_(true)
+            { }
+            XMLFile(const ClassTreeMask& mask, const std::string& filename, const std::string& resourceGroup = "General")
+                : filename_(filename)
+                , group_(resourceGroup)
+                , mask_(mask)
+                , bLuaSupport_(true)
+            { }
+
+            void setLuaSupport(bool val) { bLuaSupport_ = val; }
 
             const std::string& getFilename() const { return this->filename_; }
+            const std::string& getResourceGroup() const { return this->group_; }
             const ClassTreeMask& getMask() const { return this->mask_; }
+            bool getLuaSupport() const { return this->bLuaSupport_; }
 
         private:
             std::string filename_;
+            std::string group_;
             ClassTreeMask mask_;
+            bool bLuaSupport_; // Default is true
     };
 }
Index: code/trunk/src/core/input/Button.cc
===================================================================
--- code/trunk/src/core/input/Button.cc	(revision 5693)
+++ code/trunk/src/core/input/Button.cc	(revision 5695)
@@ -59,5 +59,4 @@
         nCommands_[1]=0;
         nCommands_[2]=0;
-        this->configContainer_ = 0;
     }
 
Index: code/trunk/src/core/input/InputManager.cc
===================================================================
--- code/trunk/src/core/input/InputManager.cc	(revision 5693)
+++ code/trunk/src/core/input/InputManager.cc	(revision 5695)
@@ -41,4 +41,5 @@
 #include <boost/foreach.hpp>
 
+#include "util/Convert.h"
 #include "util/Exception.h"
 #include "util/ScopeGuard.h"
@@ -49,4 +50,5 @@
 #include "core/CommandLine.h"
 #include "core/Functor.h"
+#include "core/GraphicsManager.h"
 
 #include "InputBuffer.h"
@@ -82,9 +84,9 @@
     // ##########                                        ##########
     // ############################################################
-    InputManager::InputManager(size_t windowHnd)
+    InputManager::InputManager()
         : internalState_(Bad)
         , oisInputManager_(0)
         , devices_(2)
-        , windowHnd_(0)
+        , bExclusiveMouse_(false)
         , emptyState_(0)
         , keyDetector_(0)
@@ -97,5 +99,5 @@
         this->setConfigValues();
 
-        this->loadDevices(windowHnd);
+        this->loadDevices();
 
         // Lowest priority empty InputState
@@ -147,6 +149,4 @@
         Creates the OIS::InputMananger, the keyboard, the mouse and
         the joys ticks. If either of the first two fail, this method throws an exception.
-    @param windowHnd
-        The window handle of the render window
     @param windowWidth
         The width of the render window
@@ -154,7 +154,7 @@
         The height of the render window
     */
-    void InputManager::loadDevices(size_t windowHnd)
-    {
-        CCOUT(3) << "Loading input devices..." << std::endl;
+    void InputManager::loadDevices()
+    {
+        CCOUT(4) << "Loading input devices..." << std::endl;
 
         // When loading the devices they should not already be loaded
@@ -164,28 +164,40 @@
         assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
 
-        // store handle internally so we can reload OIS
-        windowHnd_ = windowHnd;
-
+        // Fill parameter list
         OIS::ParamList paramList;
-        std::ostringstream windowHndStr;
-
-        // Fill parameter list
-        windowHndStr << static_cast<unsigned int>(windowHnd);
-        paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
+        size_t windowHnd = GraphicsManager::getInstance().getRenderWindowHandle();
+        paramList.insert(std::make_pair("WINDOW", multi_cast<std::string>(windowHnd)));
 #if defined(ORXONOX_PLATFORM_WINDOWS)
-        //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
-        //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
-        //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
-        //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
+        paramList.insert(std::make_pair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
+        paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
+        paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
+        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
+        {
+            // Disable Windows key plus special keys (like play, stop, next, etc.)
+            paramList.insert(std::make_pair("w32_keyboard", "DISCL_NOWINKEY"));
+            paramList.insert(std::make_pair("w32_mouse", "DISCL_EXCLUSIVE"));
+        }
+        else
+            paramList.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE"));
 #elif defined(ORXONOX_PLATFORM_LINUX)
-        paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
-        paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true"));
-        paramList.insert(std::make_pair(std::string("x11_mouse_hide"), "true"));
-        bool kbNoGrab;
-        CommandLine::getValue("keyboard_no_grab", &kbNoGrab);
-        if (kbNoGrab)
-            paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false")));
+        // Enabling this is probably a bad idea, but whenever orxonox crashes, the setting stays on
+        // Trouble might be that the Pressed event occurs a bit too often...
+        paramList.insert(std::make_pair("XAutoRepeatOn", "true"));
+
+        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
+        {
+            if (CommandLine::getValue("keyboard_no_grab").getBool())
+                paramList.insert(std::make_pair("x11_keyboard_grab", "false"));
+            else
+                paramList.insert(std::make_pair("x11_keyboard_grab", "true"));
+            paramList.insert(std::make_pair("x11_mouse_grab",  "true"));
+            paramList.insert(std::make_pair("x11_mouse_hide", "true"));
+        }
         else
-            paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("true")));
+        {
+            paramList.insert(std::make_pair("x11_keyboard_grab", "false"));
+            paramList.insert(std::make_pair("x11_mouse_grab",  "false"));
+            paramList.insert(std::make_pair("x11_mouse_hide", "false"));
+        }
 #endif
 
@@ -212,5 +224,4 @@
         }
 
-        // TODO: Remove the two parameters
         this->loadMouse();
         this->loadJoySticks();
@@ -219,5 +230,5 @@
         this->updateActiveStates();
 
-        CCOUT(3) << "Input devices loaded." << std::endl;
+        CCOUT(4) << "Input devices loaded." << std::endl;
     }
 
@@ -275,5 +286,5 @@
     InputManager::~InputManager()
     {
-        CCOUT(4) << "Destroying..." << std::endl;
+        CCOUT(3) << "Destroying..." << std::endl;
 
         // Destroy calibrator helper handler and state
@@ -293,5 +304,5 @@
             this->destroyDevices();
 
-        CCOUT(4) << "Destruction complete." << std::endl;
+        CCOUT(3) << "Destruction complete." << std::endl;
     }
 
@@ -304,5 +315,5 @@
     void InputManager::destroyDevices()
     {
-        CCOUT(3) << "Destroying devices..." << std::endl;
+        CCOUT(4) << "Destroying devices..." << std::endl;
 
         BOOST_FOREACH(InputDevice*& device, devices_)
@@ -336,5 +347,5 @@
 
         internalState_ |= Bad;
-        CCOUT(3) << "Destroyed devices." << std::endl;
+        CCOUT(4) << "Destroyed devices." << std::endl;
     }
 
@@ -365,9 +376,9 @@
 
         this->destroyDevices();
-        this->loadDevices(windowHnd_);
+        this->loadDevices();
 
         internalState_ &= ~Bad;
         internalState_ &= ~ReloadRequest;
-        CCOUT(3) << "Reloading complete." << std::endl;
+        CCOUT(4) << "Reloading complete." << std::endl;
     }
 
@@ -481,4 +492,5 @@
     void InputManager::updateActiveStates()
     {
+        assert((internalState_ & InputManager::Ticking) == 0);
         // temporary resize
         for (unsigned int i = 0; i < devices_.size(); ++i)
@@ -512,4 +524,14 @@
         for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
             activeStatesTicked_.push_back(*it);
+
+        // Check whether we have to change the mouse mode
+        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
+        if (mouseStates.empty() && bExclusiveMouse_ ||
+            !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_)
+        {
+            bExclusiveMouse_ = !bExclusiveMouse_;
+            if (!GraphicsManager::getInstance().isFullScreen())
+                this->reloadInternal();
+        }
     }
 
@@ -556,6 +578,18 @@
     }
 
-    // ############################################################
-    // #####                    Iput States                   #####
+    std::pair<int, int> InputManager::getMousePosition() const
+    {
+        Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]);
+        if (mouse != NULL)
+        {
+            const OIS::MouseState state = mouse->getOISDevice()->getMouseState();
+            return std::make_pair(state.X.abs, state.Y.abs);
+        }
+        else
+            return std::make_pair(0, 0);
+    }
+
+    // ############################################################
+    // #####                    Input States                  #####
     // ##########                                        ##########
     // ############################################################
Index: code/trunk/src/core/input/InputManager.h
===================================================================
--- code/trunk/src/core/input/InputManager.h	(revision 5693)
+++ code/trunk/src/core/input/InputManager.h	(revision 5695)
@@ -84,5 +84,5 @@
             the constructor fails with an std::exception.
         */
-        InputManager(size_t windowHnd);
+        InputManager();
         //! Destroys all devices AND all input states!
         ~InputManager();
@@ -167,6 +167,6 @@
             { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
         //! Returns a pointer to the OIS InputManager. Only you if you know what you're doing!
-        OIS::InputManager* getOISInputManager()
-            { return this->oisInputManager_; }
+        OIS::InputManager* getOISInputManager() { return this->oisInputManager_; }
+        std::pair<int, int> getMousePosition() const;
 
     private: // functions
@@ -175,5 +175,5 @@
 
         // Intenal methods
-        void loadDevices(size_t windowHnd);
+        void loadDevices();
         void loadMouse();
         void loadJoySticks();
@@ -193,6 +193,5 @@
         OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
         std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
-        // TODO: Get this from the GraphicsManager during reload
-        size_t                              windowHnd_;            //!< Render window handle (used to reload the InputManager)
+        bool                                bExclusiveMouse_;      //!< Currently applied mouse mode
 
         // some internally handled states and handlers
Index: code/trunk/src/core/input/InputState.cc
===================================================================
--- code/trunk/src/core/input/InputState.cc	(revision 5693)
+++ code/trunk/src/core/input/InputState.cc	(revision 5695)
@@ -37,4 +37,5 @@
         , bAlwaysGetsInput_(bAlwaysGetsInput)
         , bTransparent_(bTransparent)
+        , bExclusiveMouse_(true)
         , bExpired_(true)
         , handlers_(2)
Index: code/trunk/src/core/input/InputState.h
===================================================================
--- code/trunk/src/core/input/InputState.h	(revision 5693)
+++ code/trunk/src/core/input/InputState.h	(revision 5695)
@@ -75,6 +75,5 @@
           not influence ony other InputState at all.
 
-        Priorities
-        **********
+    @par Priorities
         Every InputState has a priority when on the stack, but mostly this
         priority is dynamic (InputStatePriority::Dynamic) which means that a state
@@ -83,4 +82,11 @@
         a high priority (InputStatePriority::HighPriority). These 'special' ones
         are used for features like the KeyDetector or the console. Use with care!
+
+    @par Exclusive/Non-Exclusive mouse Mode
+        You can select a specific mouse mode that tells whether the application
+        should have exclusive accessto it or not.
+        When in non-exclusive mode, you can move the mouse out of the window
+        like with any other normal window (only for windowed mode!).
+        The setting is dictated by the topmost InputState that gets mouse events.
     */
     class _CoreExport InputState : public JoyStickQuantityListener
@@ -114,4 +120,7 @@
         void setHandler        (InputHandler* handler);
 
+        void setIsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }
+        bool getIsExclusiveMouse() const { return bExclusiveMouse_; }
+
         //! Returns the name of the state (which is unique!)
         const std::string& getName() const { return name_; }
@@ -165,4 +174,5 @@
         const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
         const bool                  bTransparent_;          //!< See class declaration for explanation
+        bool                        bExclusiveMouse_;       //!< See class declaration for explanation
         int                         priority_;              //!< Current priority (might change)
         bool                        bExpired_;              //!< See hasExpired()
Index: code/trunk/src/core/input/KeyBinder.cc
===================================================================
--- code/trunk/src/core/input/KeyBinder.cc	(revision 5693)
+++ code/trunk/src/core/input/KeyBinder.cc	(revision 5695)
@@ -55,7 +55,4 @@
         mousePosition_[0] = 0;
         mousePosition_[1] = 0;
-
-        joyStickButtons_.reserve(1000);
-        joyStickAxes_.reserve(1000);
 
         RegisterRootObject(KeyBinder);
@@ -167,7 +164,7 @@
             {
                 for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
-                    joyStickButtons_[iDev][i].readConfigValue(this->configFile_);
+                    (*joyStickButtons_[iDev])[i].readConfigValue(this->configFile_);
                 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
-                    joyStickAxes_[iDev][i].readConfigValue(this->configFile_);
+                    (*joyStickAxes_[iDev])[i].readConfigValue(this->configFile_);
             }
         }
@@ -179,4 +176,9 @@
     void KeyBinder::initialiseJoyStickBindings()
     {
+        while (joyStickAxes_.size() < joySticks_.size())
+            joyStickAxes_.push_back(shared_ptr<JoyStickAxisVector>(new JoyStickAxisVector()));
+        while (joyStickButtons_.size() < joySticks_.size())
+            joyStickButtons_.push_back(shared_ptr<JoyStickButtonVector>(new JoyStickButtonVector()));
+        // For the case the new size is smaller
         this->joyStickAxes_.resize(joySticks_.size());
         this->joyStickButtons_.resize(joySticks_.size());
@@ -189,18 +191,18 @@
             for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
             {
-                joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i];
-                joyStickButtons_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
-                joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName;
+                (*joyStickButtons_[iDev])[i].name_ = JoyStickButtonCode::ByString[i];
+                (*joyStickButtons_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
+                (*joyStickButtons_[iDev])[i].groupName_ = "JoyStickButtons_" + deviceName;
             }
             // joy stick axes
             for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
             {
-                joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2];
+                (*joyStickAxes_[iDev])[i].name_ = JoyStickAxisCode::ByString[i / 2];
                 if (i & 1)
-                    joyStickAxes_[iDev][i].name_ += "Pos";
+                    (*joyStickAxes_[iDev])[i].name_ += "Pos";
                 else
-                    joyStickAxes_[iDev][i].name_ += "Neg";
-                joyStickAxes_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
-                joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName;
+                    (*joyStickAxes_[iDev])[i].name_ += "Neg";
+                (*joyStickAxes_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
+                (*joyStickAxes_[iDev])[i].groupName_ = "JoyStickAxes_" + deviceName;
             }
         }
@@ -226,9 +228,9 @@
         {
             for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
-                allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
+                allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + "." + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
             for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
             {
-                allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
-                allHalfAxes_.push_back(&(joyStickAxes_[iDev][i]));
+                allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + "." + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
+                allHalfAxes_.push_back(&((*joyStickAxes_[iDev])[i]));
             }
         }
@@ -303,6 +305,6 @@
             for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
             {
-                joyStickAxes_[iDev][i].absVal_ = 0.0f;
-                joyStickAxes_[iDev][i].relVal_ = 0.0f;
+                (*joyStickAxes_[iDev])[i].absVal_ = 0.0f;
+                (*joyStickAxes_[iDev])[i].relVal_ = 0.0f;
             }
         }
@@ -366,5 +368,5 @@
         for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
         {
-            tickHalfAxis(joyStickAxes_[joyStick][i]);
+            tickHalfAxis((*joyStickAxes_[joyStick])[i]);
         }
     }
@@ -481,5 +483,5 @@
     {
         int i = axisID * 2;
-        JoyStickAxisVector& axis = joyStickAxes_[device];
+        JoyStickAxisVector& axis = *joyStickAxes_[device];
         if (value < 0)
         {
Index: code/trunk/src/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/core/input/KeyBinder.h	(revision 5693)
+++ code/trunk/src/core/input/KeyBinder.h	(revision 5695)
@@ -41,4 +41,5 @@
 #include <string>
 #include <vector>
+#include <boost/shared_ptr.hpp>
 
 #include "InputHandler.h"
@@ -115,5 +116,5 @@
         };
         //! Actual key bindings for joy stick buttons
-        std::vector<JoyStickButtonVector> joyStickButtons_;
+        std::vector<shared_ptr<JoyStickButtonVector> > joyStickButtons_;
         //! Helper class to use something like std:vector<HalfAxis[48]>
         struct JoyStickAxisVector
@@ -123,5 +124,5 @@
         };
         //! Actual key bindings for joy stick axes (and sliders)
-        std::vector<JoyStickAxisVector> joyStickAxes_;
+        std::vector<shared_ptr<JoyStickAxisVector> > joyStickAxes_;
 
         //! Pointer map with all Buttons, including half axes
@@ -191,11 +192,11 @@
 
     inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button)
-    { joyStickButtons_[device][button].execute(KeybindMode::OnPress); }
+    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress); }
 
     inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button)
-    { joyStickButtons_[device][button].execute(KeybindMode::OnRelease); }
+    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease); }
 
     inline void KeyBinder::buttonHeld    (unsigned int device, JoyStickButtonCode::ByEnum button)
-    { joyStickButtons_[device][button].execute(KeybindMode::OnHold); }
+    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnHold); }
 
     inline void KeyBinder::allDevicesUpdated(float dt)
Index: code/trunk/src/core/input/KeyDetector.cc
===================================================================
--- code/trunk/src/core/input/KeyDetector.cc	(revision 5693)
+++ code/trunk/src/core/input/KeyDetector.cc	(revision 5695)
@@ -70,5 +70,6 @@
     {
         KeyBinder::JoyStickQuantityChanged(joyStickList);
-        setCallbackCommand(callbackCommand_);
+        if (!callbackCommand_.empty())
+            setCallbackCommand(callbackCommand_);
     }
 }
