mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 04:50:45 -05:00
Clean up logging, add progress bars
This commit is contained in:
parent
33e68f4ca7
commit
b3a676f044
@ -1,5 +1,6 @@
|
|||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using ReCodeIt.Utils;
|
||||||
|
|
||||||
namespace ReCodeIt.ReMapper;
|
namespace ReCodeIt.ReMapper;
|
||||||
|
|
||||||
@ -13,11 +14,15 @@ internal static class SPTPublicizer
|
|||||||
|
|
||||||
MainModule = definition;
|
MainModule = definition;
|
||||||
|
|
||||||
|
var typeCount = types.Where(t => !t.IsNested).Count();
|
||||||
|
var count = 0;
|
||||||
foreach (var type in types)
|
foreach (var type in types)
|
||||||
{
|
{
|
||||||
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
|
if (type.IsNested) continue; // Nested types are handled when publicizing the parent type
|
||||||
|
|
||||||
PublicizeType(type, isLauncher);
|
PublicizeType(type, isLauncher);
|
||||||
|
Logger.DrawProgressBar(count, typeCount - 1, 50);
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,8 @@ public class ReCodeItRemapper
|
|||||||
GenerateDynamicRemaps(assemblyPath, types);
|
GenerateDynamicRemaps(assemblyPath, types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogSync("Finding Best Matches...", ConsoleColor.Green);
|
||||||
|
|
||||||
var tasks = new List<Task>(remapModels.Count);
|
var tasks = new List<Task>(remapModels.Count);
|
||||||
foreach (var remap in remapModels)
|
foreach (var remap in remapModels)
|
||||||
{
|
{
|
||||||
@ -95,6 +97,12 @@ public class ReCodeItRemapper
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!tasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
|
||||||
|
{
|
||||||
|
Logger.DrawProgressBar(tasks.Where(t => t.IsCompleted)!.Count(), tasks.Count, 50);
|
||||||
|
}
|
||||||
|
|
||||||
Task.WaitAll(tasks.ToArray());
|
Task.WaitAll(tasks.ToArray());
|
||||||
|
|
||||||
ChooseBestMatches();
|
ChooseBestMatches();
|
||||||
@ -106,6 +114,8 @@ public class ReCodeItRemapper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogSync("\nRenaming...", ConsoleColor.Green);
|
||||||
|
|
||||||
var renameTasks = new List<Task>(remapModels.Count);
|
var renameTasks = new List<Task>(remapModels.Count);
|
||||||
foreach (var remap in remapModels)
|
foreach (var remap in remapModels)
|
||||||
{
|
{
|
||||||
@ -116,12 +126,18 @@ public class ReCodeItRemapper
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!renameTasks.TrueForAll(t => t.Status == TaskStatus.RanToCompletion))
|
||||||
|
{
|
||||||
|
Logger.DrawProgressBar(renameTasks.Where(t => t.IsCompleted)!.Count(), tasks.Count - 1, 50);
|
||||||
|
}
|
||||||
|
|
||||||
Task.WaitAll(renameTasks.ToArray());
|
Task.WaitAll(renameTasks.ToArray());
|
||||||
|
|
||||||
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
|
// Don't publicize and unseal until after the remapping, so we can use those as search parameters
|
||||||
if (Settings!.MappingSettings!.Publicize)
|
if (Settings!.MappingSettings!.Publicize)
|
||||||
{
|
{
|
||||||
Logger.Log("Publicizing classes...", ConsoleColor.Yellow);
|
Logger.LogSync("\nPublicizing classes...", ConsoleColor.Green);
|
||||||
|
|
||||||
SPTPublicizer.PublicizeClasses(Module);
|
SPTPublicizer.PublicizeClasses(Module);
|
||||||
}
|
}
|
||||||
@ -494,8 +510,6 @@ public class ReCodeItRemapper
|
|||||||
{
|
{
|
||||||
if (!type.Value.Name.StartsWith("GClass")) continue;
|
if (!type.Value.Name.StartsWith("GClass")) continue;
|
||||||
|
|
||||||
Logger.Log($"Key: {type.Key} Type: {type.Value.Name} Associated to {template._name}", ConsoleColor.Green);
|
|
||||||
|
|
||||||
var remap = new RemapModel
|
var remap = new RemapModel
|
||||||
{
|
{
|
||||||
OriginalTypeName = type.Value.Name,
|
OriginalTypeName = type.Value.Name,
|
||||||
@ -507,7 +521,7 @@ public class ReCodeItRemapper
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Found no association for key: {type.Key} Type: {type.Value}", ConsoleColor.Yellow);
|
// Logger.Log($"Found no association for key: {type.Key} Type: {type.Value}", ConsoleColor.Yellow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,7 +591,7 @@ public class ReCodeItRemapper
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log("Creating Hollow...", ConsoleColor.Yellow);
|
Logger.Log("\nCreating Hollow...", ConsoleColor.Yellow);
|
||||||
Hollow();
|
Hollow();
|
||||||
|
|
||||||
var hollowedDir = Path.GetDirectoryName(OutPath);
|
var hollowedDir = Path.GetDirectoryName(OutPath);
|
||||||
|
@ -41,8 +41,6 @@ internal static class RenameHelper
|
|||||||
|
|
||||||
FixMethods(types, remap);
|
FixMethods(types, remap);
|
||||||
RenameType(types, remap);
|
RenameType(types, remap);
|
||||||
|
|
||||||
Logger.Log($"{remap!.TypePrimeCandidate!.Name.String} Renamed.", ConsoleColor.Green);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FixMethods(
|
private static void FixMethods(
|
||||||
|
@ -36,8 +36,6 @@ public static class DataProvider
|
|||||||
};
|
};
|
||||||
|
|
||||||
Settings = JsonConvert.DeserializeObject<Settings>(jsonText, settings);
|
Settings = JsonConvert.DeserializeObject<Settings>(jsonText, settings);
|
||||||
|
|
||||||
Logger.Log($"Settings loaded from '{settingsPath}'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveAppSettings()
|
public static void SaveAppSettings()
|
||||||
@ -76,11 +74,7 @@ public static class DataProvider
|
|||||||
|
|
||||||
var remaps = JsonConvert.DeserializeObject<List<RemapModel>>(jsonText);
|
var remaps = JsonConvert.DeserializeObject<List<RemapModel>>(jsonText);
|
||||||
|
|
||||||
if (remaps == null) { return []; }
|
return remaps!;
|
||||||
|
|
||||||
Logger.Log($"Mapping file loaded from '{path}' containing {remaps.Count} remaps");
|
|
||||||
|
|
||||||
return remaps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveMapping()
|
public static void SaveMapping()
|
||||||
|
@ -82,6 +82,20 @@ public static class Logger
|
|||||||
return !IsTerminated;
|
return !IsTerminated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DrawProgressBar(int progress, int total, int width)
|
||||||
|
{
|
||||||
|
Console.CursorVisible = false;
|
||||||
|
Console.SetCursorPosition(0, Console.CursorTop);
|
||||||
|
|
||||||
|
double percentage = (double)progress / total;
|
||||||
|
int completed = (int)(percentage * width);
|
||||||
|
|
||||||
|
Console.Write("[");
|
||||||
|
Console.Write(new string('=', completed)); // Completed part
|
||||||
|
Console.Write(new string(' ', width - completed)); // Remaining part
|
||||||
|
Console.Write($"] {progress}/{total} ({percentage:P0})");
|
||||||
|
}
|
||||||
|
|
||||||
private const string _defaultFileName = "ReCodeIt.log";
|
private const string _defaultFileName = "ReCodeIt.log";
|
||||||
private static string _logPath => Path.Combine(AppContext.BaseDirectory, "Data", "ReCodeIt.log");
|
private static string _logPath => Path.Combine(AppContext.BaseDirectory, "Data", "ReCodeIt.log");
|
||||||
public static void ClearLog()
|
public static void ClearLog()
|
||||||
@ -98,6 +112,13 @@ public static class Logger
|
|||||||
_messages.Enqueue(new LogMessage {Message = message, Color = color, Silent = silent, ThreadId = Thread.CurrentThread.ManagedThreadId});
|
_messages.Enqueue(new LogMessage {Message = message, Color = color, Silent = silent, ThreadId = Thread.CurrentThread.ManagedThreadId});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void LogSync(string message, ConsoleColor color = ConsoleColor.White)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = color;
|
||||||
|
Console.WriteLine(message);
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
private static void LogInternal(LogMessage message)
|
private static void LogInternal(LogMessage message)
|
||||||
{
|
{
|
||||||
if (!message.Silent)
|
if (!message.Silent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user