From f8ba0a41afb8eb6a790f1ce2583c00ce421f1a66 Mon Sep 17 00:00:00 2001 From: HetCreep Date: Mon, 8 Jun 2026 19:36:17 +0700 Subject: [PATCH] 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 --- .../Il2CppInteropManager.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Runtimes/Unity/BepInEx.Unity.IL2CPP/Il2CppInteropManager.cs b/Runtimes/Unity/BepInEx.Unity.IL2CPP/Il2CppInteropManager.cs index 69fa85c..fe9de89 100644 --- a/Runtimes/Unity/BepInEx.Unity.IL2CPP/Il2CppInteropManager.cs +++ b/Runtimes/Unity/BepInEx.Unity.IL2CPP/Il2CppInteropManager.cs @@ -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; + } } }