forked from teamnwah/openmw-tes3coop
[Server] Properly load Mono libraries
This commit is contained in:
parent
c36b692e91
commit
4601884931
4 changed files with 54 additions and 22 deletions
|
@ -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
|
||||
|
|
|
@ -71,7 +71,12 @@ std::vector<MonoClass *> 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<MonoClass *> list = getInstanceClassList(instance->image, "Instance");
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// Created by koncord on 19.03.16.
|
||||
//
|
||||
|
||||
#include <apps/openmw-mp/Script/LangMono/LangMono.hpp>
|
||||
#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
|
||||
#ifdef _WIN32
|
||||
if (strstr(path, ".dll"))
|
||||
#else
|
||||
if (strstr(path, ".so"))
|
||||
try
|
||||
{
|
||||
lang = new LangMono();
|
||||
Load(lang, path);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,10 @@
|
|||
#include "Utils.hpp"
|
||||
|
||||
#include <apps/openmw-mp/Script/Script.hpp>
|
||||
|
||||
#ifdef ENABLE_MONO
|
||||
#include <mono/metadata/assembly.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BREAKPAD
|
||||
#include <handler/exception_handler.h>
|
||||
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue