From 409b169f6a595e66ef60d1e0e7b51538b12a6def Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Sat, 11 Jan 2025 06:35:18 -0500 Subject: [PATCH] Make publicizer initialization consistent with the other steps --- RecodeItLib/Remapper/Publicizer.cs | 32 +++--------------------------- RecodeItLib/Remapper/ReMapper.cs | 27 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/RecodeItLib/Remapper/Publicizer.cs b/RecodeItLib/Remapper/Publicizer.cs index 15ec63a..5846158 100644 --- a/RecodeItLib/Remapper/Publicizer.cs +++ b/RecodeItLib/Remapper/Publicizer.cs @@ -5,33 +5,7 @@ namespace ReCodeItLib.ReMapper; internal class Publicizer { - public void PublicizeClasses(ModuleDefMD definition, bool isLauncher = false) - { - var types = definition.GetTypes(); - - var publicizeTasks = new List(types.Count(t => !t.IsNested)); - foreach (var type in types) - { - if (type.IsNested) continue; // Nested types are handled when publicizing the parent type - - publicizeTasks.Add( - Task.Factory.StartNew(() => - { - PublicizeType(type, isLauncher); - }) - ); - } - - // TODO: This is broken. No idea why. - while (!publicizeTasks.TrueForAll(t => t.Status is TaskStatus.RanToCompletion or TaskStatus.Faulted)) - { - Logger.DrawProgressBar(publicizeTasks.Count(t => t.IsCompleted), publicizeTasks.Count, 50); - } - - Task.WaitAll(publicizeTasks.ToArray()); - } - - private static void PublicizeType(TypeDef type, bool isLauncher) + public void PublicizeType(TypeDef type) { // if (type.CustomAttributes.Any(a => a.AttributeType.Name == // nameof(CompilerGeneratedAttribute))) { return; } @@ -45,7 +19,7 @@ internal class Publicizer } } - if (type.IsSealed && !isLauncher) + if (type.IsSealed) { type.Attributes &= ~TypeAttributes.Sealed; // Remove the Sealed attribute if it exists } @@ -63,7 +37,7 @@ internal class Publicizer foreach (var nestedType in type.NestedTypes) { - PublicizeType(nestedType, isLauncher); + PublicizeType(nestedType); } } diff --git a/RecodeItLib/Remapper/ReMapper.cs b/RecodeItLib/Remapper/ReMapper.cs index 10f5db2..53a4d1a 100644 --- a/RecodeItLib/Remapper/ReMapper.cs +++ b/RecodeItLib/Remapper/ReMapper.cs @@ -125,10 +125,31 @@ public class ReMapper private void Publicize() { - // Don't publicize and unseal until after the remapping, so we can use those as search parameters Logger.LogSync("\nPublicizing classes...", ConsoleColor.Green); + + var publicizer = new Publicizer(); + + var publicizeTasks = new List(Module!.Types.Count(t => !t.IsNested)); + foreach (var type in Module!.Types) + { + if (type.IsNested) continue; // Nested types are handled when publicizing the parent type + + publicizeTasks.Add( + Task.Run(() => + { + try + { + publicizer.PublicizeType(type); + } + catch (Exception ex) + { + Logger.LogSync($"Exception in task: {ex.Message}", ConsoleColor.Red); + } + }) + ); + } - new Publicizer().PublicizeClasses(Module); + Task.WaitAll(publicizeTasks.ToArray()); } private bool Validate(List remaps) @@ -355,7 +376,7 @@ public class ReMapper /// private void StartHollow() { - Logger.LogSync("\nCreating Hollow...", ConsoleColor.Green); + Logger.LogSync("Creating Hollow...", ConsoleColor.Green); var tasks = new List(Module!.GetTypes().Count()); foreach (var type in Module.GetTypes())