Reputation: 11
I am trying to load assemblies from a mono game using mono_domain_assembly_open
however I have to set the full path to the assembly in order for it to load which is causing considerable lag when resolving classes, methods, and fields.
On other games i've worked on without having to set the full path in mono_domain_assembly_open
I am able to resolve with no issues or lag at all.
Why do I have to manually set the path in this game and how can I change it?
The domain I am using is the root domain I get from mono_get_root_domain
I don't completely understand how mono works internally as I'm just working with apps that are compiled with mono.
Full code:
void Mono::Attach()
{
domain = mono_get_root_domain();
mono_thread_attach(domain);
}
void Mono::Initialize()
{
Memory::Initialize(); //for resolving exports
API::Initialize(); //also for resolving exports
Mono::Attach();
}
void Class::Methods()
{
void* iter = nullptr;
MonoMethod* method;
while (method = mono_class_get_methods(this, &iter))
{
std::cout << mono_method_full_name(method, 1) << "\n";
}
}
std::string GetPath(const char* Asm)
{
//gather full path to assembly
return "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Green Hell\\GH_Data\\Managed\\" + std::string(Asm) + ".dll";
}
Assembly* Assembly::Resolve(const char* Name)
{
//need to pass full path to get the assembly
//if i dont it will return a nullptr with assembly not found exception
return (Assembly*)mono_domain_assembly_open(Mono::domain, API::GetPath(Name).c_str());
}
Class* Class::Resolve(const char* Asm, const char* Namespace, const char* Klass)
{
return (Class*)mono_class_from_name(Assembly::Resolve(Asm)->GetImage(), Namespace, Klass);
}
DWORD WINAPI MainThread(LPVOID lpReserved)
{
Mono::Initialize();
Class::Resolve("Assembly-CSharp", "", "Player")->Methods();
return TRUE;
}
I've already tried using mono_set_dirs
, mono_set_assemblies_path
, and even using full path instances to no avail. It's like since I am having to pass a large path to mono_domain_assembly_open it takes up more resources and causes lag
Upvotes: 1
Views: 80
Reputation: 151
I dont know if you are dealing with unity but if you are you many need to load the dll "mono-2.0-bdwgc.dll" instead of "mono.dll" because its what contains the desired functions under unity. An example of what i mean can be seen below.
Upvotes: 0