From ce04a24fb2965c8fa63c3fe1074d42ec28e93d42 Mon Sep 17 00:00:00 2001 From: ghorsington Date: Wed, 12 Jan 2022 20:56:12 +0200 Subject: [PATCH] ProxyAssemblyGenerator: Handle exceptions better --- BepInEx.IL2CPP/ProxyAssemblyGenerator.cs | 35 ++++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs b/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs index 4f498fb..238aa89 100644 --- a/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs +++ b/BepInEx.IL2CPP/ProxyAssemblyGenerator.cs @@ -145,18 +145,19 @@ internal static class ProxyAssemblyGenerator }); var runner = - (AppDomainRunner) AppDomainHelper.CreateInstanceAndUnwrap(domain, - typeof(AppDomainRunner).Assembly.FullName, - typeof(AppDomainRunner).FullName); + (AppDomainRunner)AppDomainHelper.CreateInstanceAndUnwrap(domain, + typeof(AppDomainRunner).Assembly.FullName, + typeof(AppDomainRunner).FullName); runner.Setup(Paths.ExecutablePath, Preloader.IL2CPPUnhollowedPath, Paths.BepInExRootPath, Paths.ManagedPath); - runner.GenerateAssembliesInternal(new AppDomainListener(), Preloader.UnityVersion.ToString(3), - ConfigIl2CppDumperType.Value); + var ok = runner.GenerateAssemblies(new AppDomainListener(), Preloader.UnityVersion.ToString(3), + ConfigIl2CppDumperType.Value); AppDomain.Unload(domain); - File.WriteAllText(HashPath, ComputeHash()); + if (ok) + File.WriteAllText(HashPath, ComputeHash()); } internal enum IL2CPPDumperType @@ -221,9 +222,25 @@ internal static class ProxyAssemblyGenerator AppDomain.CurrentDomain.AddCecilPlatformAssemblies(UnityBaseLibsDirectory); } - public void GenerateAssembliesInternal(AppDomainListener listener, - string unityVersion, - IL2CPPDumperType dumperType) + public bool GenerateAssemblies(AppDomainListener listener, + string unityVersion, + IL2CPPDumperType dumperType) + { + try + { + GenerateAssembliesInternal(listener, unityVersion, dumperType); + return true; + } + catch (Exception e) + { + listener.DoUnhollowerLog($"Failed to generate unhollowed assemblies: {e}", LogLevel.Fatal); + return false; + } + } + + private void GenerateAssembliesInternal(AppDomainListener listener, + string unityVersion, + IL2CPPDumperType dumperType) { var source = ConfigUnityBaseLibrariesSource.Value.Replace("{VERSION}", unityVersion);