mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 09:50:44 -05:00
More filter work, add prompts
This commit is contained in:
parent
02a6c417ab
commit
17df885ea8
@ -33,10 +33,11 @@ public class AutoMatchCommand : ICommand
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(MappingsPath))
|
if (!string.IsNullOrEmpty(MappingsPath))
|
||||||
{
|
{
|
||||||
|
Logger.LogSync("Loaded mapping file", ConsoleColor.Green);
|
||||||
remaps.AddRange(DataProvider.LoadMappingFile(MappingsPath));
|
remaps.AddRange(DataProvider.LoadMappingFile(MappingsPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
new AutoMatcher(remaps)
|
new AutoMatcher(remaps, MappingsPath)
|
||||||
.AutoMatch(AssemblyPath, OldTypeName, NewTypeName);
|
.AutoMatch(AssemblyPath, OldTypeName, NewTypeName);
|
||||||
|
|
||||||
// Wait for log termination
|
// Wait for log termination
|
||||||
|
@ -4,7 +4,7 @@ using ReCodeItLib.Utils;
|
|||||||
|
|
||||||
namespace ReCodeItLib.ReMapper;
|
namespace ReCodeItLib.ReMapper;
|
||||||
|
|
||||||
public class AutoMatcher(List<RemapModel> mappings)
|
public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
||||||
{
|
{
|
||||||
private ModuleDefMD? Module { get; set; }
|
private ModuleDefMD? Module { get; set; }
|
||||||
|
|
||||||
@ -81,6 +81,8 @@ public class AutoMatcher(List<RemapModel> mappings)
|
|||||||
};
|
};
|
||||||
|
|
||||||
new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true);
|
new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true);
|
||||||
|
|
||||||
|
ProcessEndQuestions(remapModel, assemblyPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +157,14 @@ public class AutoMatcher(List<RemapModel> mappings)
|
|||||||
|
|
||||||
methods.ExcludeMethods.AddRange(excludeMethods);
|
methods.ExcludeMethods.AddRange(excludeMethods);
|
||||||
|
|
||||||
|
methods.MethodCount = target.Methods
|
||||||
|
.Count(m => !m.IsConstructor && !m.IsGetter && !m.IsSetter && !m.IsSpecialName);
|
||||||
|
|
||||||
|
if (target.Methods.Any(m => m.IsConstructor && m.Parameters.Count > 0))
|
||||||
|
{
|
||||||
|
methods.ConstructorParameterCount = target.Methods.First(m => m.IsConstructor && m.Parameters.Count > 0).Parameters.Count - 1;
|
||||||
|
}
|
||||||
|
|
||||||
return commonMethods.Any();
|
return commonMethods.Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +205,8 @@ public class AutoMatcher(List<RemapModel> mappings)
|
|||||||
|
|
||||||
fields.ExcludeFields.AddRange(excludeFields);
|
fields.ExcludeFields.AddRange(excludeFields);
|
||||||
|
|
||||||
|
fields.FieldCount = target.Fields.Count;
|
||||||
|
|
||||||
return commonFields.Any();
|
return commonFields.Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,37 +247,43 @@ public class AutoMatcher(List<RemapModel> mappings)
|
|||||||
|
|
||||||
props.ExcludeProperties.AddRange(excludeProps);
|
props.ExcludeProperties.AddRange(excludeProps);
|
||||||
|
|
||||||
|
props.PropertyCount = target.Properties.Count;
|
||||||
|
|
||||||
return commonProps.Any();
|
return commonProps.Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CompareMethods(MappingDiff diff)
|
private void ProcessEndQuestions(RemapModel remapModel, string assemblyPath)
|
||||||
{
|
{
|
||||||
var diffsByTarget = diff.Target.Methods
|
Thread.Sleep(1000);
|
||||||
.Select(m => m.Name)
|
|
||||||
.Except(diff.Candidate.Methods.Select(m => m.Name))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (diffsByTarget.Any())
|
Logger.LogSync("Add remap to existing list?.. (y/n)", ConsoleColor.Yellow);
|
||||||
|
var resp = Console.ReadLine();
|
||||||
|
|
||||||
|
if (resp == "y" || resp == "yes" || resp == "Y")
|
||||||
{
|
{
|
||||||
Logger.LogSync($"Methods in target not present in candidate:\n {string.Join(", ", diffsByTarget)}", ConsoleColor.Yellow);
|
if (mappings.Count == 0)
|
||||||
}
|
|
||||||
|
|
||||||
var diffsByCandidate = diff.Candidate.Methods
|
|
||||||
.Select(m => m.Name)
|
|
||||||
.Except(diff.Target.Methods.Select(m => m.Name))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (diffsByCandidate.Any())
|
|
||||||
{
|
{
|
||||||
Logger.LogSync($"Methods in candidate not present in target:\n {string.Join(", ", diffsByCandidate)}", ConsoleColor.Yellow);
|
Logger.LogSync("No remaps loaded. Please restart with a provided mapping path.", ConsoleColor.Red);
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MappingDiff
|
if (mappings.Any(m => m.NewTypeName == remapModel.NewTypeName))
|
||||||
{
|
{
|
||||||
public required TypeDef Target;
|
Logger.LogSync($"Ambiguous new type names found for {remapModel.NewTypeName}. Please pick a different name.", ConsoleColor.Red);
|
||||||
public required TypeDef Candidate;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public RemapModel RemapModel = new();
|
mappings.Add(remapModel);
|
||||||
|
DataProvider.UpdateMapping(mappingPath, mappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.LogSync("Would you like to run the remap process?... (y/n)", ConsoleColor.Yellow);
|
||||||
|
var resp2 = Console.ReadLine();
|
||||||
|
|
||||||
|
if (resp2 == "y" || resp2 == "yes" || resp2 == "Y")
|
||||||
|
{
|
||||||
|
var outPath = Path.GetDirectoryName(assemblyPath);
|
||||||
|
new ReMapper().InitializeRemap(mappings, assemblyPath, outPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user