0
0
mirror of https://github.com/sp-tarkov/assembly-tool.git synced 2025-02-13 01:30:45 -05:00

Nested type support

This commit is contained in:
Cj 2025-01-01 21:10:31 -05:00
parent 3dbdfae549
commit 4c82026a84
2 changed files with 62 additions and 7 deletions

View File

@ -35,6 +35,8 @@ public class RemapModel
public bool UseForceRename { get; set; }
public bool? AutoGenerated { get; set; } = null;
public SearchParams SearchParams { get; set; } = new();
}

View File

@ -72,6 +72,12 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
}
if (!ContainsTargetProperties(target, candidate, remapModel.SearchParams.Properties))
{
CandidateTypes!.Remove(candidate);
continue;
}
if (!ContainsTargetNestedTypes(target, candidate, remapModel.SearchParams.NestedTypes))
{
CandidateTypes!.Remove(candidate);
}
@ -89,7 +95,10 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true);
ProcessEndQuestions(remapModel, assemblyPath);
return;
}
Logger.LogSync("Could not find a match... :(", ConsoleColor.Red);
}
private bool PassesGeneralChecks(TypeDef target, TypeDef candidate, GenericParams parms)
@ -113,6 +122,12 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
parms.IsNested = target.IsNested;
parms.IsSealed = target.IsSealed;
parms.HasAttribute = target.HasCustomAttributes;
parms.IsDerived = target.BaseType != null && target.BaseType.Name != "Object";
if ((bool)parms.IsDerived)
{
parms.MatchBaseClass = target.BaseType?.Name.String;
}
return true;
}
@ -188,9 +203,6 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
return true;
}
// Target has no fields but type has fields
if (!target.Fields.Any() && candidate.Fields.Any()) return false;
// Target has fields but type has no fields
if (target.Fields.Any() && !candidate.Fields.Any()) return false;
@ -235,9 +247,6 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
return true;
}
// Target has no props but type has props
if (!target.Properties.Any() && candidate.Properties.Any()) return false;
// Target has props but type has no props
if (target.Properties.Any() && !candidate.Properties.Any()) return false;
@ -273,6 +282,48 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
return commonProps.Any();
}
private bool ContainsTargetNestedTypes(TypeDef target, TypeDef candidate, NestedTypeParams nt)
{
// Target has no nt's but type has nt's
if (!target.NestedTypes.Any() && candidate.NestedTypes.Any())
{
nt.NestedTypeCount = 0;
return false;
}
// Target has nt's but type has no nt's
if (target.NestedTypes.Any() && !candidate.NestedTypes.Any()) return false;
// Target has a different number of nt's
if (target.NestedTypes.Count != candidate.NestedTypes.Count) return false;
var commonNts = target.NestedTypes
.Select(s => s.Name)
.Intersect(candidate.NestedTypes.Select(s => s.Name));
var includeNts = target.NestedTypes
.Select(s => s.Name.ToString())
.Except(candidate.NestedTypes.Select(s => s.Name.ToString()));
var excludeNts = candidate.NestedTypes
.Select(s => s.Name.ToString())
.Except(target.NestedTypes.Select(s => s.Name.ToString()));
foreach (var include in includeNts)
{
nt.IncludeNestedTypes.Add(include);
}
foreach (var exclude in excludeNts)
{
nt.ExcludeNestedTypes.Add(exclude);
}
nt.NestedTypeCount = target.NestedTypes.Count;
return commonNts.Any() || !target.IsNested;
}
private void ProcessEndQuestions(RemapModel remapModel, string assemblyPath)
{
Thread.Sleep(1000);
@ -294,6 +345,8 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
return;
}
remapModel.AutoGenerated = true;
mappings.Add(remapModel);
DataProvider.UpdateMapping(mappingPath, mappings);
}