From c841ee8ec3825c7d3508ef239f58e8a35d8e6307 Mon Sep 17 00:00:00 2001 From: js6pak Date: Mon, 21 Jun 2021 21:56:07 +0200 Subject: [PATCH 1/2] Add automatic downloading of unity base libraries --- BepInEx.IL2CPP/Preloader.cs | 13 +++++----- BepInEx.IL2CPP/ProxyAssemblyGenerator.cs | 33 ++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/BepInEx.IL2CPP/Preloader.cs b/BepInEx.IL2CPP/Preloader.cs index 68eb6fd..303a573 100644 --- a/BepInEx.IL2CPP/Preloader.cs +++ b/BepInEx.IL2CPP/Preloader.cs @@ -23,6 +23,8 @@ namespace BepInEx.IL2CPP // TODO: This is not needed, maybe remove? (Instance is saved in IL2CPPChainloader itself) private static IL2CPPChainloader Chainloader { get; set; } + public static Version UnityVersion { get; private set; } + public static void Run() { try @@ -51,13 +53,12 @@ namespace BepInEx.IL2CPP LogSupport.TraceHandler += UnhollowerLog.LogDebug; LogSupport.ErrorHandler += UnhollowerLog.LogError; + InitializeUnityVersion(); if (ProxyAssemblyGenerator.CheckIfGenerationRequired()) ProxyAssemblyGenerator.GenerateAssemblies(); - - - InitializeUnityVersion(); + UnityVersionHandler.Initialize(UnityVersion.Major, UnityVersion.Minor, UnityVersion.Build); using (var assemblyPatcher = new AssemblyPatcher()) { @@ -123,8 +124,8 @@ namespace BepInEx.IL2CPP return false; } - UnityVersionHandler.Initialize(major, minor, build); - Log.LogInfo($"Running under Unity v{major}.{minor}.{build}"); + UnityVersion = new Version(major, minor, build); + Log.LogInfo($"Running under Unity v{UnityVersion}"); return true; } catch (Exception ex) @@ -143,4 +144,4 @@ namespace BepInEx.IL2CPP #endregion } -} \ No newline at end of file +} diff --git a/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs b/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs index 9cc235b..8d42763 100644 --- a/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs +++ b/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs @@ -1,8 +1,11 @@ using System; using System.IO; +using System.IO.Compression; +using System.Net.Http; using System.Security.Cryptography; using System.Text; using AssemblyUnhollower; +using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Il2CppDumper; @@ -12,6 +15,11 @@ namespace BepInEx.IL2CPP { internal static class ProxyAssemblyGenerator { + private static readonly ConfigEntry ConfigUnityBaseLibrariesSource = ConfigFile.CoreConfig.Bind( + "IL2CPP", "UnityBaseLibrariesSource", + "http://unitylibs.bepinex.dev/{VERSION}.zip", + "Source of the unity base libraries downloaded at runtime. If empty, nothing will be downloaded."); + private static readonly ManualLogSource Il2cppDumperLogger = Logger.CreateLogSource("Il2CppDumper"); public static string GameAssemblyPath => Path.Combine(Paths.GameRootPath, "GameAssembly.dll"); @@ -74,7 +82,7 @@ namespace BepInEx.IL2CPP runner.Setup(Paths.ExecutablePath, Preloader.IL2CPPUnhollowedPath, Paths.BepInExRootPath, Paths.ManagedPath); - runner.GenerateAssembliesInternal(new AppDomainListener()); + runner.GenerateAssembliesInternal(new AppDomainListener(), Preloader.UnityVersion.ToString(3)); AppDomain.Unload(domain); @@ -137,8 +145,29 @@ namespace BepInEx.IL2CPP AppDomain.CurrentDomain.AddCecilPlatformAssemblies(UnityBaseLibsDirectory); } - public void GenerateAssembliesInternal(AppDomainListener listener) + public void GenerateAssembliesInternal(AppDomainListener listener, string unityVersion) { + var source = + ConfigUnityBaseLibrariesSource.Value.Replace("{VERSION}", unityVersion); + + if (!string.IsNullOrEmpty(source)) + { + listener.DoPreloaderLog("Downloading unity base libraries", LogLevel.Message); + + Directory.CreateDirectory(UnityBaseLibsDirectory); + + foreach (var dllFile in Directory.EnumerateFiles(UnityBaseLibsDirectory, "*.dll")) + { + File.Delete(dllFile); + } + + using var httpClient = new HttpClient(); + using var zipStream = httpClient.GetStreamAsync(source).GetAwaiter().GetResult(); + using var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Read); + + zipArchive.ExtractToDirectory(UnityBaseLibsDirectory); + } + listener.DoPreloaderLog("Generating Il2CppUnhollower assemblies", LogLevel.Message); Directory.CreateDirectory(Preloader.IL2CPPUnhollowedPath); From 4cf47c85da5463ef98ccbf9033b73b7de2a51d0b Mon Sep 17 00:00:00 2001 From: js6pak Date: Wed, 23 Jun 2021 00:00:30 +0200 Subject: [PATCH 2/2] Update default url --- BepInEx.IL2CPP/ProxyAssemblyGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs b/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs index 8d42763..65f763f 100644 --- a/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs +++ b/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs @@ -17,7 +17,7 @@ namespace BepInEx.IL2CPP { private static readonly ConfigEntry ConfigUnityBaseLibrariesSource = ConfigFile.CoreConfig.Bind( "IL2CPP", "UnityBaseLibrariesSource", - "http://unitylibs.bepinex.dev/{VERSION}.zip", + "http://unity.bepinex.dev/libraries/{VERSION}.zip", "Source of the unity base libraries downloaded at runtime. If empty, nothing will be downloaded."); private static readonly ManualLogSource Il2cppDumperLogger = Logger.CreateLogSource("Il2CppDumper");