diff --git a/AssemblyRemapper/Models/RemapModel.cs b/AssemblyRemapper/Models/RemapModel.cs index 6444815..be130d1 100644 --- a/AssemblyRemapper/Models/RemapModel.cs +++ b/AssemblyRemapper/Models/RemapModel.cs @@ -43,4 +43,8 @@ internal class SearchParams public SearchParams() { } +} + +internal class AdvancedSearchParams +{ } \ No newline at end of file diff --git a/AssemblyRemapper/Models/ScoringModel.cs b/AssemblyRemapper/Models/ScoringModel.cs index 353f2eb..5709dee 100644 --- a/AssemblyRemapper/Models/ScoringModel.cs +++ b/AssemblyRemapper/Models/ScoringModel.cs @@ -48,4 +48,32 @@ internal static class ScoringModelExtensions Console.WriteLine(e.ToString()); } } + + 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; + + if (value is HashSet hashset) + { + maxScore += hashset.Count * 2; + } + else + { + maxScore++; + } + } + + return maxScore; + } } \ No newline at end of file diff --git a/AssemblyRemapper/Reflection/Remapper.cs b/AssemblyRemapper/Reflection/Remapper.cs index 78dcaef..7698e12 100644 --- a/AssemblyRemapper/Reflection/Remapper.cs +++ b/AssemblyRemapper/Reflection/Remapper.cs @@ -251,6 +251,18 @@ internal class Remapper Logger.Log("-----------------------------------------------", ConsoleColor.Green); Logger.Log($"Renaming {highestScore.Definition.Name} to {highestScore.ProposedNewName}", ConsoleColor.Green); + Logger.Log($"Max possible score: {highestScore.CalculateMaxScore()}", ConsoleColor.Green); + Logger.Log($"Scored: {highestScore.Score} points", ConsoleColor.Green); + + if (scores.Count > 1) + { + Logger.Log($"Warning! There were {scores.Count} possible matches. Considering adding more search parameters", ConsoleColor.Yellow); + + foreach (var score in scores) + { + Logger.Log($"{score.Definition.Name} - Score [{score.Score}]", ConsoleColor.Yellow); + } + } // Rename type and all associated type members RenameService.RenameAll(highestScore); diff --git a/AssemblyRemapper/Reflection/RenameService.cs b/AssemblyRemapper/Reflection/RenameService.cs index e94d75e..8dd3b08 100644 --- a/AssemblyRemapper/Reflection/RenameService.cs +++ b/AssemblyRemapper/Reflection/RenameService.cs @@ -16,8 +16,6 @@ internal static class RenameService RenameAllProperties(score, types); score.Definition.Name = score.ProposedNewName; - - types.FirstOrDefault(t => t.Name == score.ProposedNewName).Name = score.ProposedNewName; } public static void RenameAllDirect(RemapModel remap, TypeDefinition type) @@ -44,7 +42,7 @@ internal static class RenameService if (field.Name == newFieldName) { continue; } - Logger.Log($"Renaming field: `{field.Name}` on Type `{type.Name}` to {newFieldName}"); + Logger.Log($"Renaming field: `{field.Name}` on Type `{type.Name}` to {newFieldName}", ConsoleColor.Green); field.Name = newFieldName; @@ -76,7 +74,7 @@ internal static class RenameService { var newName = propertyCount > 0 ? $"{score.RemapModel.NewTypeName}_{propertyCount}" : score.RemapModel.NewTypeName; - Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}` to {newName}"); + Logger.Log($"Renaming Property: `{property.Name}` on Type `{type}` to {newName}", ConsoleColor.Green); property.Name = newName; } }