2024-06-12 18:59:08 -04:00
|
|
|
|
using AssemblyRemapper.Enums;
|
|
|
|
|
using AssemblyRemapper.Utils;
|
2024-06-11 19:18:48 -04:00
|
|
|
|
using Mono.Cecil;
|
|
|
|
|
|
|
|
|
|
namespace AssemblyRemapper.Models;
|
|
|
|
|
|
|
|
|
|
internal class ScoringModel
|
|
|
|
|
{
|
|
|
|
|
public string ProposedNewName { get; set; }
|
2024-06-12 00:05:59 -04:00
|
|
|
|
public int Score { get; set; } = 0;
|
2024-06-11 19:18:48 -04:00
|
|
|
|
public TypeDefinition Definition { get; set; }
|
2024-06-12 00:05:59 -04:00
|
|
|
|
public RemapModel RemapModel { get; internal set; }
|
2024-06-11 19:18:48 -04:00
|
|
|
|
|
2024-06-12 18:59:08 -04:00
|
|
|
|
public EFailureReason FailureReason { get; set; } = EFailureReason.None;
|
|
|
|
|
|
2024-06-11 19:18:48 -04:00
|
|
|
|
public ScoringModel()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static class ScoringModelExtensions
|
|
|
|
|
{
|
2024-06-12 19:42:16 -04:00
|
|
|
|
public static void AddScoreToResult(this ScoringModel model)
|
2024-06-11 19:18:48 -04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-06-11 23:07:59 -04:00
|
|
|
|
if (DataProvider.ScoringModels.TryGetValue(model.ProposedNewName, out HashSet<ScoringModel> modelHashset))
|
2024-06-11 19:18:48 -04:00
|
|
|
|
{
|
2024-06-11 23:07:59 -04:00
|
|
|
|
foreach (var outVal in modelHashset)
|
|
|
|
|
{
|
2024-06-12 19:42:16 -04:00
|
|
|
|
if (outVal.Definition.Name == model.Definition.Name)
|
2024-06-11 23:07:59 -04:00
|
|
|
|
{
|
|
|
|
|
Logger.Log("Skipping adding duplicate type match to list", ConsoleColor.Yellow);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-11 19:18:48 -04:00
|
|
|
|
modelHashset.Add(model);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var newHash = new HashSet<ScoringModel>
|
|
|
|
|
{
|
|
|
|
|
model
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-11 23:07:59 -04:00
|
|
|
|
DataProvider.ScoringModels.Add(model.ProposedNewName, newHash);
|
2024-06-11 19:18:48 -04:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-12 15:47:11 -04:00
|
|
|
|
|
|
|
|
|
public static int CalculateMaxScore(this ScoringModel score)
|
|
|
|
|
{
|
|
|
|
|
// Score should never be null here, but if it is we're fucked so just return 0.
|
|
|
|
|
if (score == null) { return 0; }
|
|
|
|
|
|
|
|
|
|
var propInfos = typeof(SearchParams).GetProperties();
|
|
|
|
|
|
|
|
|
|
int maxScore = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var propInfo in propInfos)
|
|
|
|
|
{
|
|
|
|
|
object value = propInfo.GetValue(score.RemapModel.SearchParams);
|
|
|
|
|
|
|
|
|
|
if (value == null) continue;
|
|
|
|
|
|
2024-06-12 18:59:08 -04:00
|
|
|
|
if (value is List<string> list)
|
2024-06-12 15:47:11 -04:00
|
|
|
|
{
|
2024-06-12 18:59:08 -04:00
|
|
|
|
maxScore += list.Count;
|
2024-06-12 15:47:11 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
maxScore++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return maxScore;
|
|
|
|
|
}
|
2024-06-11 19:18:48 -04:00
|
|
|
|
}
|