diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 642c62e20..d3b37ad69 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -44,6 +44,7 @@ if(BUILD_WITH_MONO) set(MonoScript_Headers Script/LangMono/LangMono.hpp ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MONO") endif(BUILD_WITH_MONO) set(NativeScript_Sources diff --git a/apps/openmw-mp/Script/LangMono/LangMono.cpp b/apps/openmw-mp/Script/LangMono/LangMono.cpp index 8068ab371..1a4a107f7 100644 --- a/apps/openmw-mp/Script/LangMono/LangMono.cpp +++ b/apps/openmw-mp/Script/LangMono/LangMono.cpp @@ -71,7 +71,12 @@ std::vector getInstanceClassList(MonoImage *image, const std::strin void LangMono::LoadProgram(const char *filename) { - instance->assembly = mono_domain_assembly_open(domain, filename); + MonoAssembly *assembly = mono_domain_assembly_open(domain, filename); + + if(!assembly) + throw std::runtime_error("Cannot load: " + std::string(filename)); + + instance->assembly = assembly; instance->image = mono_assembly_get_image(instance->assembly); std::vector list = getInstanceClassList(instance->image, "Instance"); diff --git a/apps/openmw-mp/Script/Script.cpp b/apps/openmw-mp/Script/Script.cpp index 2c357bdb3..30f41a0ce 100644 --- a/apps/openmw-mp/Script/Script.cpp +++ b/apps/openmw-mp/Script/Script.cpp @@ -2,7 +2,6 @@ // Created by koncord on 19.03.16. // -#include #include "Script.hpp" #include "LangNative/LangNative.hpp" @@ -10,11 +9,28 @@ #include "LangLua/LangLua.hpp" #endif +#ifdef ENABLE_MONO +#include "LangMono/LangMono.hpp" +#endif + using namespace std; Script::ScriptList Script::scripts; std::string Script::moddir; +inline bool Load(Language *lang, const std::string &path) +{ + try + { + lang->LoadProgram(path.c_str()); + } + catch (...) + { + lang->FreeProgram(); + throw std::runtime_error("Failed to load: " + path); + } +} + Script::Script(const char *path) { FILE *file = fopen(path, "rb"); @@ -26,39 +42,43 @@ Script::Script(const char *path) if (strstr(path, ".dll")) { +#ifdef ENABLE_MONO script_type = SCRIPT_MONO; - lang = new LangMono(); - } - /*else + try + { + lang = new LangMono(); + Load(lang, path); + } + catch(...) + { +#endif #ifdef _WIN32 - if (strstr(path, ".dll")) -#else - if (strstr(path, ".so")) + script_type = SCRIPT_CPP; + lang = new LangNative(); + Load(lang, path); +#endif +#ifdef ENABLE_MONO + } #endif + } +#ifndef _WIN32 + else if (strstr(path, ".so")) { script_type = SCRIPT_CPP; lang = new LangNative(); - }*/ + Load(lang, path); + } +#endif #if defined (ENABLE_LUA) else if (strstr(path, ".lua") || strstr(path, ".t")) { - lang = new LangLua(); script_type = SCRIPT_LUA; + lang = new LangLua(); + Load(lang, path); } #endif else throw runtime_error("Script type not recognized: " + string(path)); - - try - { - lang->LoadProgram(path); - } - catch (...) - { - lang->FreeProgram(); - throw; - } - } diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index 03e5e1b93..279f2d56d 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -26,7 +26,10 @@ #include "Utils.hpp" #include + +#ifdef ENABLE_MONO #include +#endif #ifdef ENABLE_BREAKPAD #include @@ -235,7 +238,10 @@ int main(int argc, char *argv[]) #endif #endif + +#ifdef ENABLE_MONO mono_set_dirs(Utils::convertPath(plugin_home + "/mono").c_str(), Utils::convertPath(plugin_home + "/mono/etc").c_str()); +#endif int code;