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"));
