Give actionable error when base-libs download fails (#1332)

When the Unity base-libraries download fails (commonly a 404 for a
Unity version not yet hosted on unity.bepinex.dev), the uncaught
HttpRequestException surfaced only as a cryptic "Failed to generate
Il2Cpp interop assemblies" and the game would not launch -- even
though a local fallback (the unity-libs directory) already exists.

Catch the download failure and throw a clear message naming the Unity
version, the URL and the two workarounds: place a matching
base-libraries .zip in the unity-libs directory, or point the
[IL2CPP] UnityBaseLibrariesSource config at a valid URL.

Refs #1295, #1084, #986, #941, #515
This commit is contained in:
HetCreep authored and GitHub committed 2026-06-08 14:36:17 +02:00
1 parent 3fab71a191
commit f8ba0a41af
1 file changed
+24 -7
@@ -303,17 +303,34 @@ internal static partial class Il2CppInteropManager
Logger.LogMessage($"Downloading unity base libraries from {source}");
using var httpClient = new HttpClient();
using var zipStream = httpClient.GetStreamAsync(uri).GetAwaiter().GetResult();
Stream zipStream;
try
{
using var writeStream = new FileStream(zipFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
zipStream.CopyTo(writeStream);
zipStream = httpClient.GetStreamAsync(uri).GetAwaiter().GetResult();
}
catch
catch (Exception e)
{
// Delete the incomplete file to avoid issues on next startup
try { File.Delete(zipFilePath); } catch { }
throw;
throw new IOException(
$"Failed to download Unity base libraries for Unity {unityVersion} from {source}: {e.Message}. " +
$"Base libraries for this Unity version may not be available on the server yet. Download a matching " +
$"base-libraries .zip and place it in the \"{UnityBaseLibsDirectory}\" (unity-libs) directory, or set " +
$"the [IL2CPP] UnityBaseLibrariesSource config option to a valid URL.", e);
}
using (zipStream)
{
try
{
using var writeStream = new FileStream(zipFilePath, FileMode.Create, FileAccess.Write, FileShare.None);
zipStream.CopyTo(writeStream);
}
catch
{
// Delete the incomplete file to avoid issues on next startup
try { File.Delete(zipFilePath); } catch { }
throw;
}
}
}