Skip to content

Commit 8ed7da6

Browse files
committed
support most (all?) mono path/filename variations
1 parent 35c7840 commit 8ed7da6

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

UnityAssemblyInjector/Main.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,20 +242,48 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser
242242
}
243243
}
244244

245-
auto LoadMono = [&](std::string path)
246-
{
247-
const char* monoPath = va("%s\\%s\\mono.dll", dataDirectory.c_str(), path.c_str());
245+
std::vector<std::string> searchPaths = {
246+
"Mono",
247+
"Mono\\EmbedRuntime",
248+
"MonoBleedingEdge\\EmbedRuntime"
249+
};
248250

249-
monoHandle = LoadLibraryA(monoPath);
251+
std::vector<std::string> searchNames = {
252+
"mono.dll", // older mono builds
253+
"mono-2.0-bdwgc.dll", // unity gc mono builds
254+
"mono-2.0-sgen.dll", // oficial gc mono builds
255+
"mono-2.0-boehm.dll" // official mono builds with boehm's gc
250256
};
251257

252-
LoadMono("Mono\\EmbedRuntime");
253-
254-
if (!monoHandle)
258+
std::string monoPath = "";
259+
260+
for (auto& path : searchPaths)
255261
{
256-
LoadMono("Mono");
262+
for (auto& name : searchNames)
263+
{
264+
std::string tryPath = va("%s\\%s\\%s", dataDirectory.c_str(), path.c_str(), name.c_str());
265+
266+
if (std::filesystem::exists(tryPath))
267+
{
268+
monoPath = tryPath;
269+
break;
270+
}
271+
}
272+
273+
if (monoPath != "")
274+
{
275+
break;
276+
}
257277
}
258278

279+
if (monoPath == "")
280+
{
281+
DBGPRINT(L"Couldn't find mono.dll");
282+
return false;
283+
}
284+
285+
monoHandle = LoadLibraryA(monoPath.c_str());
286+
259287
if (!monoHandle)
260288
{
261289
DBGPRINT(L"Failed to load mono.dll");

0 commit comments

Comments
 (0)