Index: code/trunk/src/core/CMakeLists.txt
===================================================================
--- code/trunk/src/core/CMakeLists.txt	(revision 3370)
+++ code/trunk/src/core/CMakeLists.txt	(revision 5693)
@@ -23,4 +23,6 @@
   ConfigValueContainer.cc
   Core.cc
+  DynLib.cc
+  DynLibManager.cc
   Event.cc
   Game.cc
Index: code/trunk/src/core/Core.cc
===================================================================
--- code/trunk/src/core/Core.cc	(revision 3370)
+++ code/trunk/src/core/Core.cc	(revision 5693)
@@ -40,4 +40,5 @@
 #include <cstdlib>
 #include <cstdio>
+#include <boost/version.hpp>
 #include <boost/filesystem.hpp>
 #include <OgreRenderWindow.h>
@@ -68,4 +69,5 @@
 #include "ConfigValueIncludes.h"
 #include "CoreIncludes.h"
+#include "DynLibManager.h"
 #include "Factory.h"
 #include "GameMode.h"
@@ -80,4 +82,11 @@
 #include "input/InputManager.h"
 
+// Boost 1.36 has some issues with deprecated functions that have been omitted
+#if (BOOST_VERSION == 103600)
+#  define BOOST_LEAF_FUNCTION filename
+#else
+#  define BOOST_LEAF_FUNCTION leaf
+#endif
+
 namespace orxonox
 {
@@ -241,4 +250,5 @@
         boost::filesystem::path rootPath_;
         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 configPath_;            //!< Path to the config file folder
@@ -256,16 +266,73 @@
         , bGraphicsLoaded_(false)
     {
-        // Parse command line arguments first
+        // Set the hard coded fixed paths
+        this->setFixedPaths();
+
+        // Create a new dynamic library manager
+        this->dynLibManager_.reset(new DynLibManager());
+
+        // Load modules
+        try
+        {
+            // We search for helper files with the following extension
+            std::string moduleextension = ORXONOX_MODULE_EXTENSION;
+            size_t moduleextensionlength = moduleextension.size();
+
+            // Search in the directory of our executable
+            boost::filesystem::path searchpath = this->configuration_->modulePath_;
+
+            // Add that path to the PATH variable in case a module depends on another one
+            std::string pathVariable = getenv("PATH");
+            putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str()));
+
+            boost::filesystem::directory_iterator file(searchpath);
+            boost::filesystem::directory_iterator end;
+
+            // Iterate through all files
+            while (file != end)
+            {
+                std::string filename = file->BOOST_LEAF_FUNCTION();
+
+                // Check if the file ends with the exension in question
+                if (filename.size() > moduleextensionlength)
+                {
+                    if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
+                    {
+                        // We've found a helper file - now load the library with the same name
+                        std::string library = filename.substr(0, filename.size() - moduleextensionlength);
+                        boost::filesystem::path librarypath = searchpath / library;
+
+                        try
+                        {
+                            DynLibManager::getInstance().load(librarypath.string());
+                        }
+                        catch (const std::exception& e)
+                        {
+                            COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << e.what() << std::endl;
+                        }
+                        catch (...)
+                        {
+                            COUT(1) << "Couldn't load module \"" << librarypath.string() << "\"" << std::endl;
+                        }
+                    }
+                }
+
+                ++file;
+            }
+        }
+        catch (const std::exception& e)
+        {
+            COUT(1) << "An error occurred while loading modules: " << e.what() << std::endl;
+        }
+        catch (...)
+        {
+            COUT(1) << "An error occurred while loading modules." << std::endl;
+        }
+
+        // Parse command line arguments AFTER the modules have been loaded (static code!)
         CommandLine::parseCommandLine(cmdLine);
 
-        // Determine and set the location of the executable
-        setExecutablePath();
-
-        // Determine whether we have an installed or a binary dir run
-        // The latter occurs when simply running from the build directory
-        checkDevBuild();
-
-        // Make sure the directories we write in exist or else make them
-        createDirectories();
+        // Set configurable paths like log, config and media
+        this->setConfigurablePaths();
 
         // create a signal handler (only active for linux)
@@ -507,8 +574,17 @@
     /**
     @brief
-        Compares the executable path with the working directory
-    */
-    void Core::setExecutablePath()
-    {
+        Retrievs the executable path and sets all hard coded fixed path (currently only the module path)
+        Also checks for "orxonox_dev_build.keep_me" in the executable diretory.
+        If found it means that this is not an installed run, hence we
+        don't write the logs and config files to ~/.orxonox
+    @throw
+        GeneralException
+    */
+    void Core::setFixedPaths()
+    {
+        //////////////////////////
+        // FIND EXECUTABLE PATH //
+        //////////////////////////
+
 #ifdef ORXONOX_PLATFORM_WINDOWS
         // get executable module
@@ -553,27 +629,20 @@
         configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name
 #endif
-    }
-
-    /**
-    @brief
-        Checks for "orxonox_dev_build.keep_me" in the executable diretory.
-        If found it means that this is not an installed run, hence we
-        don't write the logs and config files to ~/.orxonox
-    @throws
-        GeneralException
-    */
-    void Core::checkDevBuild()
-    {
+
+        /////////////////////
+        // SET MODULE PATH //
+        /////////////////////
+
         if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me"))
         {
             COUT(1) << "Running from the build tree." << std::endl;
             Core::bDevRun_ = true;
-            configuration_->mediaPath_  = ORXONOX_MEDIA_DEV_PATH;
-            configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH;
-            configuration_->logPath_    = ORXONOX_LOG_DEV_PATH;
+            configuration_->modulePath_ = ORXONOX_MODULE_DEV_PATH;
         }
         else
         {
+
 #ifdef INSTALL_COPYABLE // --> relative paths
+
             // Also set the root path
             boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
@@ -585,10 +654,42 @@
                 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
 
+            // Module path is fixed as well
+            configuration_->modulePath_ = configuration_->rootPath_ / ORXONOX_MODULE_INSTALL_PATH;
+
+#else
+
+            // There is no root path, so don't set it at all
+            // Module path is fixed as well
+            configuration_->modulePath_ = ORXONOX_MODULE_INSTALL_PATH;
+
+#endif
+        }
+    }
+
+    /**
+    @brief
+        Sets config, log and media path and creates folders if necessary.
+    @throws
+        GeneralException
+    */
+    void Core::setConfigurablePaths()
+    {
+        if (Core::isDevelopmentRun())
+        {
+            configuration_->mediaPath_  = ORXONOX_MEDIA_DEV_PATH;
+            configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH;
+            configuration_->logPath_    = ORXONOX_LOG_DEV_PATH;
+        }
+        else
+        {
+
+#ifdef INSTALL_COPYABLE // --> relative paths
+
             // 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;
+
 #else
-            // There is no root path, so don't set it at all
 
             configuration_->mediaPath_  = ORXONOX_MEDIA_INSTALL_PATH;
@@ -607,5 +708,7 @@
             configuration_->configPath_ = userDataPath / ORXONOX_CONFIG_INSTALL_PATH;
             configuration_->logPath_    = userDataPath / ORXONOX_LOG_INSTALL_PATH;
-#endif
+
+#endif
+
         }
 
@@ -617,15 +720,6 @@
             configuration_->logPath_    = configuration_->logPath_    / directory;
         }
-    }
-
-    /*
-    @brief
-        Checks for the log and the config directory and creates them
-        if necessary. Otherwise me might have problems opening those files.
-    @throws
-        orxonox::GeneralException if the directory to be created is a file.
-    */
-    void Core::createDirectories()
-    {
+
+        // Create directories to avoid problems when opening files in non existent folders.
         std::vector<std::pair<boost::filesystem::path, std::string> > directories;
         directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config"));
Index: code/trunk/src/core/Core.h
===================================================================
--- code/trunk/src/core/Core.h	(revision 3370)
+++ code/trunk/src/core/Core.h	(revision 5693)
@@ -114,10 +114,10 @@
             Core(const Core&); //!< Don't use (undefined symbol)
 
-            void checkDevBuild();
-            void setExecutablePath();
-            void createDirectories();
+            void setFixedPaths();
+            void setConfigurablePaths();
             void setThreadAffinity(int limitToCPU);
 
             // Mind the order for the destruction!
+            scoped_ptr<DynLibManager>     dynLibManager_;
             scoped_ptr<SignalHandler>     signalHandler_;
             SimpleScopeGuard              identifierDestroyer_;
Index: code/trunk/src/core/CorePrereqs.h
===================================================================
--- code/trunk/src/core/CorePrereqs.h	(revision 3370)
+++ code/trunk/src/core/CorePrereqs.h	(revision 5693)
@@ -112,4 +112,6 @@
     class ConsoleCommand;
     class Core;
+    class DynLib;
+    class DynLibManager;
     struct Event;
     class EventContainer;
Index: code/trunk/src/core/DynLib.cc
===================================================================
--- code/trunk/src/core/DynLib.cc	(revision 5693)
+++ code/trunk/src/core/DynLib.cc	(revision 5693)
@@ -0,0 +1,134 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser 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 Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+#include "DynLib.h"
+
+#include "util/Exception.h"
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+#  define WIN32_LEAN_AND_MEAN
+#  ifndef NOMINMAX
+#    define NOMINMAX // required to stop windows.h messing up std::min
+#  endif
+#  include <windows.h>
+#endif
+
+#ifdef ORXONOX_PLATFORM_APPLE
+#   include "macPlugins.h"
+#endif
+
+namespace orxonox
+{
+    //-----------------------------------------------------------------------
+    DynLib::DynLib( const std::string& name )
+    {
+        mName = name;
+        m_hInst = NULL;
+    }
+
+    //-----------------------------------------------------------------------
+    DynLib::~DynLib()
+    {
+    }
+
+    //-----------------------------------------------------------------------
+    void DynLib::load()
+    {
+        // Log library load
+        COUT(2) << "Loading module " << mName << std::endl;
+
+		std::string name = mName;
+#ifdef ORXONOX_PLATFORM_LINUX
+        // dlopen() does not add .so to the filename, like windows does for .dll
+        if (name.substr(name.length() - 3, 3) != ".so")
+           name += ".so";
+#endif
+
+        m_hInst = (DYNLIB_HANDLE)DYNLIB_LOAD( name.c_str() );
+
+        if( !m_hInst )
+            ThrowException(
+                General,
+                "Could not load dynamic library " + mName +
+                ".  System Error: " + dynlibError());
+    }
+
+    //-----------------------------------------------------------------------
+    void DynLib::unload()
+    {
+        // Log library unload
+        COUT(4) << "Unloading module " << mName << std::endl;
+
+        if( DYNLIB_UNLOAD( m_hInst ) )
+		{
+            ThrowException(
+                General,
+                "Could not unload dynamic library " + mName +
+                ".  System Error: " + dynlibError());
+		}
+
+    }
+
+    //-----------------------------------------------------------------------
+    void* DynLib::getSymbol( const std::string& strName ) const throw()
+    {
+        return (void*)DYNLIB_GETSYM( m_hInst, strName.c_str() );
+    }
+    //-----------------------------------------------------------------------
+    std::string DynLib::dynlibError( void )
+    {
+#if defined(ORXONOX_PLATFORM_WINDOWS)
+        LPVOID lpMsgBuf;
+        FormatMessage(
+            FORMAT_MESSAGE_ALLOCATE_BUFFER |
+            FORMAT_MESSAGE_FROM_SYSTEM |
+            FORMAT_MESSAGE_IGNORE_INSERTS,
+            NULL,
+            GetLastError(),
+            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+            (LPTSTR) &lpMsgBuf,
+            0,
+            NULL
+            );
+        std::string ret = (char*)lpMsgBuf;
+        // Free the buffer.
+        LocalFree( lpMsgBuf );
+        return ret;
+#elif defined(ORXONOX_PLATFORM_LINUX)
+        return std::string(dlerror());
+#elif defined(ORXONOX_PLATFORM_APPLE)
+        return std::string(mac_errorBundle());
+#else
+        return std::string("");
+#endif
+    }
+
+}
Index: code/trunk/src/core/DynLib.h
===================================================================
--- code/trunk/src/core/DynLib.h	(revision 5693)
+++ code/trunk/src/core/DynLib.h	(revision 5693)
@@ -0,0 +1,121 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser 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 Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+#ifndef _Core_DynLib_H__
+#define _Core_DynLib_H__
+
+#include "CorePrereqs.h"
+
+#include <string>
+
+#if defined(ORXONOX_PLATFORM_WINDOWS)
+#    define DYNLIB_HANDLE hInstance
+#    define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
+#    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
+#    define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
+
+struct HINSTANCE__;
+typedef struct HINSTANCE__* hInstance;
+
+#elif defined(ORXONOX_PLATFORM_LINUX)
+#    define DYNLIB_HANDLE void*
+#    define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
+#    define DYNLIB_GETSYM( a, b ) dlsym( a, b )
+#    define DYNLIB_UNLOAD( a ) dlclose( a )
+
+#elif defined(ORXONOX_PLATFORM_APPLE)
+#    define DYNLIB_HANDLE CFBundleRef
+#    define DYNLIB_LOAD( a ) mac_loadExeBundle( a )
+#    define DYNLIB_GETSYM( a, b ) mac_getBundleSym( a, b )
+#    define DYNLIB_UNLOAD( a ) mac_unloadExeBundle( a )
+#endif
+
+namespace orxonox
+{
+    /** Resource holding data about a dynamic library.
+        @remarks
+            This class holds the data required to get symbols from
+            libraries loaded at run-time (i.e. from DLL's for so's)
+        @author
+            Adrian Cearnãu (cearny@cearny.ro)
+        @since
+            27 January 2002
+        @see
+            Resource
+    */
+	class _CoreExport DynLib
+    {
+	protected:
+		std::string mName;
+        /// Gets the last loading error
+        std::string dynlibError(void);
+    public:
+        /** Default constructor - used by DynLibManager.
+            @warning
+                Do not call directly
+        */
+        DynLib( const std::string& name );
+
+        /** Default destructor.
+        */
+        ~DynLib();
+
+        /** Load the library
+        */
+        void load();
+        /** Unload the library
+        */
+        void unload();
+		/// Get the name of the library
+		const std::string& getName(void) const { return mName; }
+
+        /**
+            Returns the address of the given symbol from the loaded library.
+            @param
+                strName The name of the symbol to search for
+            @returns
+                If the function succeeds, the returned value is a handle to
+                the symbol.
+            @par
+                If the function fails, the returned value is <b>NULL</b>.
+
+        */
+        void* getSymbol( const std::string& strName ) const throw();
+
+    protected:
+
+        /// Handle to the loaded library.
+        DYNLIB_HANDLE m_hInst;
+    };
+
+}
+
+#endif /* _Core_DynLib_H__ */
Index: code/trunk/src/core/DynLibManager.cc
===================================================================
--- code/trunk/src/core/DynLibManager.cc	(revision 5693)
+++ code/trunk/src/core/DynLibManager.cc	(revision 5693)
@@ -0,0 +1,86 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser 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 Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+#include "DynLibManager.h"
+
+#include "DynLib.h"
+
+namespace orxonox
+{
+    //-----------------------------------------------------------------------
+    //! Static pointer to the singleton
+    DynLibManager* DynLibManager::singletonPtr_s  = 0;
+
+    //-----------------------------------------------------------------------
+	DynLibManager::DynLibManager()
+	{
+	}
+	//-----------------------------------------------------------------------
+    DynLib* DynLibManager::load( const std::string& filename)
+    {
+		DynLibList::iterator i = mLibList.find(filename);
+		if (i != mLibList.end())
+		{
+			return i->second;
+		}
+		else
+		{
+	        DynLib* pLib = new DynLib(filename);
+			pLib->load();
+        	mLibList[filename] = pLib;
+	        return pLib;
+		}
+    }
+	//-----------------------------------------------------------------------
+	void DynLibManager::unload(DynLib* lib)
+	{
+		DynLibList::iterator i = mLibList.find(lib->getName());
+		if (i != mLibList.end())
+		{
+			mLibList.erase(i);
+		}
+		lib->unload();
+		delete lib;
+	}
+	//-----------------------------------------------------------------------
+    DynLibManager::~DynLibManager()
+    {
+        // Unload & delete resources in turn
+        for( DynLibList::iterator it = mLibList.begin(); it != mLibList.end(); ++it )
+        {
+            it->second->unload();
+            delete it->second;
+        }
+
+        // Empty the list
+        mLibList.clear();
+    }
+}
Index: code/trunk/src/core/DynLibManager.h
===================================================================
--- code/trunk/src/core/DynLibManager.h	(revision 5693)
+++ code/trunk/src/core/DynLibManager.h	(revision 5693)
@@ -0,0 +1,87 @@
+/*
+-----------------------------------------------------------------------------
+This source file is part of OGRE
+    (Object-oriented Graphics Rendering Engine)
+For the latest info, see http://www.ogre3d.org/
+
+Copyright (c) 2000-2006 Torus Knot Software Ltd
+Also see acknowledgements in Readme.html
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser 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 Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+Place - Suite 330, Boston, MA 02111-1307, USA, or go to
+http://www.gnu.org/copyleft/lesser.txt.
+
+You may alternatively use this source under the terms of a specific version of
+the OGRE Unrestricted License provided you have obtained such a license from
+Torus Knot Software Ltd.
+-----------------------------------------------------------------------------
+*/
+
+// 08/11/2009: Small adjustments for Orxonox by Fabian 'x3n' Landau
+
+#ifndef _Core_DynLibManager_H__
+#define _Core_DynLibManager_H__
+
+#include "CorePrereqs.h"
+#include "util/Singleton.h"
+
+namespace orxonox
+{
+    /** Manager for Dynamic-loading Libraries.
+        @remarks
+            This manager keeps a track of all the open dynamic-loading
+            libraries, opens them and returns references to already-open
+            libraries.
+    */
+    class _CoreExport DynLibManager: public Singleton<DynLibManager>
+    {
+        friend class Singleton<DynLibManager>;
+
+        protected:
+            typedef std::map<std::string, DynLib*> DynLibList;
+            DynLibList mLibList;
+
+        public:
+            /** Default constructor.
+                @note
+                    <br>Should never be called as the singleton is automatically
+                    created during the creation of the Root object.
+                @see
+                    Root::Root
+            */
+            DynLibManager();
+
+            /** Default destructor.
+                @see
+                    Root::~Root
+            */
+            virtual ~DynLibManager();
+
+            /** Loads the passed library.
+                @param
+                    filename The name of the library. The extension can be omitted
+            */
+            DynLib* load(const std::string& filename);
+
+            /** Unloads the passed library.
+            @param
+            filename The name of the library. The extension can be omitted
+            */
+            void unload(DynLib* lib);
+
+        private:
+            static DynLibManager* singletonPtr_s;
+    };
+}
+
+#endif /* _Core_DynLibManager_H__ */
Index: code/trunk/src/core/GUIManager.h
===================================================================
--- code/trunk/src/core/GUIManager.h	(revision 3370)
+++ code/trunk/src/core/GUIManager.h	(revision 5693)
@@ -50,4 +50,6 @@
 namespace orxonox
 {
+    class PlayerInfo; // Forward declaration
+
     /**
     @class GUIManager
@@ -77,4 +79,9 @@
         static GUIManager* getInstancePtr() { return singletonPtr_s; }
 
+        inline void setPlayer(const std::string& guiname, PlayerInfo* player)
+            { this->players_[guiname] = player; }
+        inline PlayerInfo* getPlayer(const std::string& guiname) const
+            { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; }
+
     private:
         GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
@@ -92,13 +99,14 @@
         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
+        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
 
-        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 3370)
+++ code/trunk/src/core/Game.cc	(revision 5693)
@@ -113,4 +113,6 @@
     */
     Game::Game(const std::string& cmdLine)
+        // Destroy factories before the Core!
+        : gsFactoryDestroyer_(Game::GameStateFactory::factories_s, &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
     {
         this->bAbort_ = false;
Index: code/trunk/src/core/Game.h
===================================================================
--- code/trunk/src/core/Game.h	(revision 3370)
+++ code/trunk/src/core/Game.h	(revision 5693)
@@ -48,4 +48,5 @@
 
 #include "util/Debug.h"
+#include "util/ScopeGuard.h"
 #include "util/Singleton.h"
 
@@ -85,4 +86,5 @@
         typedef std::map<std::string, shared_ptr<GameState> > GameStateMap;
         typedef boost::shared_ptr<GameStateTreeNode> GameStateTreeNodePtr;
+
     public:
         Game(const std::string& cmdLine);
@@ -118,5 +120,5 @@
             static void createFactory(const std::string& className)
                 { factories_s[className].reset(new TemplateGameStateFactory<T>()); }
-        private:
+
             virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0;
             static std::map<std::string, shared_ptr<GameStateFactory> > factories_s;
@@ -129,4 +131,6 @@
                 { return shared_ptr<GameState>(new T(info)); }
         };
+        // For the factory destruction
+        typedef Loki::ObjScopeGuardImpl0<std::map<std::string, shared_ptr<GameStateFactory> >, void (std::map<std::string, shared_ptr<GameStateFactory> >::*)()> ObjScopeGuard;
 
         struct StatisticsTickInfo
@@ -156,4 +160,5 @@
         scoped_ptr<Clock>                  gameClock_;
         scoped_ptr<Core>                   core_;
+        ObjScopeGuard                      gsFactoryDestroyer_;
         scoped_ptr<GameConfiguration>      configuration_;
 
Index: code/trunk/src/core/TclThreadList.h
===================================================================
--- code/trunk/src/core/TclThreadList.h	(revision 3370)
+++ code/trunk/src/core/TclThreadList.h	(revision 5693)
