Skip to content

Commit

Permalink
support most (all?) mono path/filename variations
Browse files Browse the repository at this point in the history
  • Loading branch information
avail committed Mar 1, 2019
1 parent 35c7840 commit 8ed7da6
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions UnityAssemblyInjector/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> searchPaths = {
"Mono",
"Mono\\EmbedRuntime",
"MonoBleedingEdge\\EmbedRuntime"
};

monoHandle = LoadLibraryA(monoPath);
std::vector<std::string> 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");
Expand Down

0 comments on commit 8ed7da6

Please sign in to comment.