Skip to content

Commit

Permalink
A bit better
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Feb 9, 2024
1 parent bea0887 commit a896970
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions Runtimes/Unity/BepInEx.Unity.IL2CPP/Il2CppInteropManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,27 +374,24 @@ internal static void PreloadInteropAssemblies()

var sw = Stopwatch.StartNew();

var dir = new DirectoryInfo(IL2CPPInteropAssemblyPath);
var files = dir.GetFiles();
var files = Directory.EnumerateFiles(IL2CPPInteropAssemblyPath);
var loaded = 0;
System.Threading.Tasks.Parallel.ForEach(files, file =>
{
if (file.Name.Equals("netstandard.dll", StringComparison.OrdinalIgnoreCase))
return;
if (file.Extension.Equals(".dll", StringComparison.OrdinalIgnoreCase))
if (!file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) return;
if (file.EndsWith("netstandard.dll", StringComparison.OrdinalIgnoreCase)) return;
try
{
var assemblyName = AssemblyName.GetAssemblyName(file);
Assembly.Load(assemblyName);
System.Threading.Interlocked.Increment(ref loaded);
}
catch (Exception e)
{
try
{
var assemblyName = AssemblyName.GetAssemblyName(file.FullName);
Assembly.Load(assemblyName);
}
catch (Exception e)
{
Logger.Log(BepInEx.Logging.LogLevel.Warning, $"Failed to preload {file.Name} - {e}");
}
Logger.Log(BepInEx.Logging.LogLevel.Warning, $"Failed to preload {file} - {e}");
}
});

Logger.Log(BepInEx.Logging.LogLevel.Debug, $"Preloaded {files.Length} assemblies in {sw.ElapsedMilliseconds}ms");
Logger.Log(BepInEx.Logging.LogLevel.Debug, $"Preloaded {loaded} interop assemblies in {sw.ElapsedMilliseconds}ms");
}
}

0 comments on commit a896970

Please sign in to comment.