From 8ed7da6236076ccdf107511750bf136d9a1ce20b Mon Sep 17 00:00:00 2001 From: avail Date: Fri, 1 Mar 2019 16:52:42 +0100 Subject: [PATCH] support most (all?) mono path/filename variations --- UnityAssemblyInjector/Main.cpp | 44 +++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/UnityAssemblyInjector/Main.cpp b/UnityAssemblyInjector/Main.cpp index 5b46b7e..ad5de68 100644 --- a/UnityAssemblyInjector/Main.cpp +++ b/UnityAssemblyInjector/Main.cpp @@ -242,20 +242,48 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser } } - auto LoadMono = [&](std::string path) - { - const char* monoPath = va("%s\\%s\\mono.dll", dataDirectory.c_str(), path.c_str()); + std::vector searchPaths = { + "Mono", + "Mono\\EmbedRuntime", + "MonoBleedingEdge\\EmbedRuntime" + }; - monoHandle = LoadLibraryA(monoPath); + std::vector searchNames = { + "mono.dll", // older mono builds + "mono-2.0-bdwgc.dll", // unity gc mono builds + "mono-2.0-sgen.dll", // oficial gc mono builds + "mono-2.0-boehm.dll" // official mono builds with boehm's gc }; - LoadMono("Mono\\EmbedRuntime"); - - if (!monoHandle) + std::string monoPath = ""; + + for (auto& path : searchPaths) { - LoadMono("Mono"); + for (auto& name : searchNames) + { + std::string tryPath = va("%s\\%s\\%s", dataDirectory.c_str(), path.c_str(), name.c_str()); + + if (std::filesystem::exists(tryPath)) + { + monoPath = tryPath; + break; + } + } + + if (monoPath != "") + { + break; + } } + if (monoPath == "") + { + DBGPRINT(L"Couldn't find mono.dll"); + return false; + } + + monoHandle = LoadLibraryA(monoPath.c_str()); + if (!monoHandle) { DBGPRINT(L"Failed to load mono.dll");