0
0
mirror of https://github.com/sp-tarkov/assembly-tool.git synced 2025-02-12 14:30:45 -05:00

Make publicizer initialization consistent with the other steps

This commit is contained in:
Cj 2025-01-11 06:35:18 -05:00
parent 2672696e3a
commit 409b169f6a
2 changed files with 27 additions and 32 deletions

View File

@ -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<Task>(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);
}
}

View File

@ -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<Task>(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<RemapModel> remaps)
@ -355,7 +376,7 @@ public class ReMapper
/// </summary>
private void StartHollow()
{
Logger.LogSync("\nCreating Hollow...", ConsoleColor.Green);
Logger.LogSync("Creating Hollow...", ConsoleColor.Green);
var tasks = new List<Task>(Module!.GetTypes().Count());
foreach (var type in Module.GetTypes())