[Server] Properly load Mono libraries

experimental-mono
Koncord 6 years ago
parent c36b692e91
commit 4601884931

@ -44,6 +44,7 @@ if(BUILD_WITH_MONO)
set(MonoScript_Headers set(MonoScript_Headers
Script/LangMono/LangMono.hpp Script/LangMono/LangMono.hpp
) )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_MONO")
endif(BUILD_WITH_MONO) endif(BUILD_WITH_MONO)
set(NativeScript_Sources set(NativeScript_Sources

@ -71,7 +71,12 @@ std::vector<MonoClass *> getInstanceClassList(MonoImage *image, const std::strin
void LangMono::LoadProgram(const char *filename) 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); instance->image = mono_assembly_get_image(instance->assembly);
std::vector<MonoClass *> list = getInstanceClassList(instance->image, "Instance"); std::vector<MonoClass *> list = getInstanceClassList(instance->image, "Instance");

@ -2,7 +2,6 @@
// Created by koncord on 19.03.16. // Created by koncord on 19.03.16.
// //
#include <apps/openmw-mp/Script/LangMono/LangMono.hpp>
#include "Script.hpp" #include "Script.hpp"
#include "LangNative/LangNative.hpp" #include "LangNative/LangNative.hpp"
@ -10,11 +9,28 @@
#include "LangLua/LangLua.hpp" #include "LangLua/LangLua.hpp"
#endif #endif
#ifdef ENABLE_MONO
#include "LangMono/LangMono.hpp"
#endif
using namespace std; using namespace std;
Script::ScriptList Script::scripts; Script::ScriptList Script::scripts;
std::string Script::moddir; 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) Script::Script(const char *path)
{ {
FILE *file = fopen(path, "rb"); FILE *file = fopen(path, "rb");
@ -26,39 +42,43 @@ Script::Script(const char *path)
if (strstr(path, ".dll")) if (strstr(path, ".dll"))
{ {
#ifdef ENABLE_MONO
script_type = SCRIPT_MONO; script_type = SCRIPT_MONO;
lang = new LangMono(); try
} {
/*else lang = new LangMono();
Load(lang, path);
}
catch(...)
{
#endif
#ifdef _WIN32 #ifdef _WIN32
if (strstr(path, ".dll")) script_type = SCRIPT_CPP;
#else lang = new LangNative();
if (strstr(path, ".so")) Load(lang, path);
#endif
#ifdef ENABLE_MONO
}
#endif #endif
}
#ifndef _WIN32
else if (strstr(path, ".so"))
{ {
script_type = SCRIPT_CPP; script_type = SCRIPT_CPP;
lang = new LangNative(); lang = new LangNative();
}*/ Load(lang, path);
}
#endif
#if defined (ENABLE_LUA) #if defined (ENABLE_LUA)
else if (strstr(path, ".lua") || strstr(path, ".t")) else if (strstr(path, ".lua") || strstr(path, ".t"))
{ {
lang = new LangLua();
script_type = SCRIPT_LUA; script_type = SCRIPT_LUA;
lang = new LangLua();
Load(lang, path);
} }
#endif #endif
else else
throw runtime_error("Script type not recognized: " + string(path)); throw runtime_error("Script type not recognized: " + string(path));
try
{
lang->LoadProgram(path);
}
catch (...)
{
lang->FreeProgram();
throw;
}
} }

@ -26,7 +26,10 @@
#include "Utils.hpp" #include "Utils.hpp"
#include <apps/openmw-mp/Script/Script.hpp> #include <apps/openmw-mp/Script/Script.hpp>
#ifdef ENABLE_MONO
#include <mono/metadata/assembly.h> #include <mono/metadata/assembly.h>
#endif
#ifdef ENABLE_BREAKPAD #ifdef ENABLE_BREAKPAD
#include <handler/exception_handler.h> #include <handler/exception_handler.h>
@ -235,7 +238,10 @@ int main(int argc, char *argv[])
#endif #endif
#endif #endif
#ifdef ENABLE_MONO
mono_set_dirs(Utils::convertPath(plugin_home + "/mono").c_str(), Utils::convertPath(plugin_home + "/mono/etc").c_str()); mono_set_dirs(Utils::convertPath(plugin_home + "/mono").c_str(), Utils::convertPath(plugin_home + "/mono/etc").c_str());
#endif
int code; int code;

Loading…
Cancel
Save