mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 04:50:45 -05:00
108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
using System.Diagnostics;
|
|
using Newtonsoft.Json;
|
|
using ReCodeItLib.Enums;
|
|
using ReCodeItLib.Models;
|
|
using ReCodeItLib.Utils;
|
|
|
|
namespace ReCodeItLib.ReMapper;
|
|
|
|
public class Statistics(
|
|
List<RemapModel> remapModels,
|
|
Stopwatch stopwatch,
|
|
string outPath,
|
|
string hollowedPath = "")
|
|
{
|
|
public void DisplayStatistics(bool validate = false)
|
|
{
|
|
DisplayAlternativeMatches();
|
|
DisplayFailuresAndChanges(validate);
|
|
|
|
if (!validate)
|
|
{
|
|
DisplayWriteAssembly();
|
|
}
|
|
}
|
|
|
|
private void DisplayAlternativeMatches()
|
|
{
|
|
foreach (var remap in remapModels)
|
|
{
|
|
if (remap.Succeeded is false) { continue; }
|
|
|
|
if (remap.TypeCandidates.Count > 1)
|
|
{
|
|
DisplayAlternativeMatches(remap);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DisplayAlternativeMatches(RemapModel remap)
|
|
{
|
|
Logger.Log($"Warning! There were {remap.TypeCandidates.Count()} possible matches for {remap.NewTypeName}. Consider adding more search parameters, Only showing the first 5.", ConsoleColor.Yellow);
|
|
|
|
foreach (var type in remap.TypeCandidates.Skip(1).Take(5))
|
|
{
|
|
Logger.Log($"{type.Name}", ConsoleColor.Yellow);
|
|
}
|
|
}
|
|
|
|
private void DisplayFailuresAndChanges(bool validate)
|
|
{
|
|
var failures = 0;
|
|
var changes = 0;
|
|
|
|
foreach (var remap in remapModels)
|
|
{
|
|
if (remap.Succeeded is false && remap.NoMatchReasons.Contains(ENoMatchReason.AmbiguousWithPreviousMatch))
|
|
{
|
|
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
|
Logger.Log("Ambiguous match with a previous match during matching. Skipping remap.", ConsoleColor.Red);
|
|
Logger.Log($"New Type Name: {remap.NewTypeName}", ConsoleColor.Red);
|
|
Logger.Log($"{remap.AmbiguousTypeMatch} already assigned to a previous match.", ConsoleColor.Red);
|
|
Logger.Log("----------------------------------------------------------------------", ConsoleColor.Red);
|
|
}
|
|
else if (remap.Succeeded is false)
|
|
{
|
|
Logger.Log("-----------------------------------------------", ConsoleColor.Red);
|
|
Logger.Log($"Renaming {remap.NewTypeName} failed with reason(s)", ConsoleColor.Red);
|
|
|
|
foreach (var reason in remap.NoMatchReasons)
|
|
{
|
|
Logger.Log($"Reason: {reason}", ConsoleColor.Red);
|
|
}
|
|
|
|
Logger.Log("-----------------------------------------------", ConsoleColor.Red);
|
|
failures++;
|
|
continue;
|
|
}
|
|
|
|
if (validate)
|
|
{
|
|
var str = JsonConvert.SerializeObject(remap, Formatting.Indented);
|
|
|
|
Logger.Log("Generated Model: ", ConsoleColor.Blue);
|
|
Logger.Log(str, ConsoleColor.Blue);
|
|
|
|
Logger.Log("Passed validation", ConsoleColor.Green);
|
|
return;
|
|
}
|
|
|
|
changes++;
|
|
}
|
|
|
|
var renamedColor = changes > 0 ? ConsoleColor.Green : ConsoleColor.Yellow;
|
|
|
|
Logger.Log($"Renamed {changes} types", renamedColor);
|
|
|
|
var failColor = failures > 0 ? ConsoleColor.Red : ConsoleColor.Green;
|
|
|
|
Logger.Log($"Failed to rename {failures} types", failColor);
|
|
}
|
|
|
|
private void DisplayWriteAssembly()
|
|
{
|
|
Logger.Log($"Assembly written to `{outPath}`", ConsoleColor.Green);
|
|
Logger.Log($"Hollowed written to `{hollowedPath}`", ConsoleColor.Green);
|
|
Logger.Log($"Remap took {stopwatch.Elapsed.TotalSeconds:F1} seconds", ConsoleColor.Green);
|
|
}
|
|
} |