mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 01:50:45 -05:00
Nested type support
This commit is contained in:
parent
3dbdfae549
commit
4c82026a84
@ -35,6 +35,8 @@ public class RemapModel
|
|||||||
|
|
||||||
public bool UseForceRename { get; set; }
|
public bool UseForceRename { get; set; }
|
||||||
|
|
||||||
|
public bool? AutoGenerated { get; set; } = null;
|
||||||
|
|
||||||
public SearchParams SearchParams { get; set; } = new();
|
public SearchParams SearchParams { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,12 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ContainsTargetProperties(target, candidate, remapModel.SearchParams.Properties))
|
if (!ContainsTargetProperties(target, candidate, remapModel.SearchParams.Properties))
|
||||||
|
{
|
||||||
|
CandidateTypes!.Remove(candidate);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ContainsTargetNestedTypes(target, candidate, remapModel.SearchParams.NestedTypes))
|
||||||
{
|
{
|
||||||
CandidateTypes!.Remove(candidate);
|
CandidateTypes!.Remove(candidate);
|
||||||
}
|
}
|
||||||
@ -89,7 +95,10 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
|||||||
new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true);
|
new ReMapper().InitializeRemap(tmpList, assemblyPath, validate: true);
|
||||||
|
|
||||||
ProcessEndQuestions(remapModel, assemblyPath);
|
ProcessEndQuestions(remapModel, assemblyPath);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogSync("Could not find a match... :(", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool PassesGeneralChecks(TypeDef target, TypeDef candidate, GenericParams parms)
|
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.IsNested = target.IsNested;
|
||||||
parms.IsSealed = target.IsSealed;
|
parms.IsSealed = target.IsSealed;
|
||||||
parms.HasAttribute = target.HasCustomAttributes;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -188,9 +203,6 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
|||||||
return true;
|
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
|
// Target has fields but type has no fields
|
||||||
if (target.Fields.Any() && !candidate.Fields.Any()) return false;
|
if (target.Fields.Any() && !candidate.Fields.Any()) return false;
|
||||||
|
|
||||||
@ -235,9 +247,6 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
|||||||
return true;
|
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
|
// Target has props but type has no props
|
||||||
if (target.Properties.Any() && !candidate.Properties.Any()) return false;
|
if (target.Properties.Any() && !candidate.Properties.Any()) return false;
|
||||||
|
|
||||||
@ -273,6 +282,48 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
|||||||
return commonProps.Any();
|
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)
|
private void ProcessEndQuestions(RemapModel remapModel, string assemblyPath)
|
||||||
{
|
{
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
@ -293,7 +344,9 @@ public class AutoMatcher(List<RemapModel> mappings, string mappingPath)
|
|||||||
Logger.LogSync($"Ambiguous new type names found for {remapModel.NewTypeName}. Please pick a different name.", ConsoleColor.Red);
|
Logger.LogSync($"Ambiguous new type names found for {remapModel.NewTypeName}. Please pick a different name.", ConsoleColor.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remapModel.AutoGenerated = true;
|
||||||
|
|
||||||
mappings.Add(remapModel);
|
mappings.Add(remapModel);
|
||||||
DataProvider.UpdateMapping(mappingPath, mappings);
|
DataProvider.UpdateMapping(mappingPath, mappings);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user