mirror of
https://github.com/sp-tarkov/assembly-tool.git
synced 2025-02-13 01:50:45 -05:00
cleanup remapper
This commit is contained in:
parent
af8afeab78
commit
9830004f42
@ -17,7 +17,7 @@ public class ReMapper
|
|||||||
|
|
||||||
private List<RemapModel> _remaps = [];
|
private List<RemapModel> _remaps = [];
|
||||||
|
|
||||||
private List<string> _alreadyGivenNames = [];
|
private readonly List<string> _alreadyGivenNames = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start the remapping process
|
/// Start the remapping process
|
||||||
@ -28,9 +28,7 @@ public class ReMapper
|
|||||||
string outPath = "",
|
string outPath = "",
|
||||||
bool validate = false)
|
bool validate = false)
|
||||||
{
|
{
|
||||||
_remaps = [];
|
|
||||||
_remaps = remapModels;
|
_remaps = remapModels;
|
||||||
_alreadyGivenNames = [];
|
|
||||||
|
|
||||||
assemblyPath = AssemblyUtils.TryDeObfuscate(
|
assemblyPath = AssemblyUtils.TryDeObfuscate(
|
||||||
DataProvider.LoadModule(assemblyPath),
|
DataProvider.LoadModule(assemblyPath),
|
||||||
@ -47,12 +45,13 @@ public class ReMapper
|
|||||||
|
|
||||||
var types = Module.GetTypes();
|
var types = Module.GetTypes();
|
||||||
|
|
||||||
|
var typeDefs = types as TypeDef[] ?? types.ToArray();
|
||||||
if (!validate)
|
if (!validate)
|
||||||
{
|
{
|
||||||
GenerateDynamicRemaps(assemblyPath, types);
|
GenerateDynamicRemaps(assemblyPath, typeDefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
FindBestMatches(types, validate);
|
FindBestMatches(typeDefs, validate);
|
||||||
ChooseBestMatches();
|
ChooseBestMatches();
|
||||||
|
|
||||||
// Don't go any further during a validation
|
// Don't go any further during a validation
|
||||||
@ -64,11 +63,8 @@ public class ReMapper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenameMatches(types);
|
RenameMatches(typeDefs);
|
||||||
|
|
||||||
Publicize();
|
Publicize();
|
||||||
|
|
||||||
// We are done, write the assembly
|
|
||||||
WriteAssembly();
|
WriteAssembly();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,16 +148,16 @@ public class ReMapper
|
|||||||
Task.WaitAll(publicizeTasks.ToArray());
|
Task.WaitAll(publicizeTasks.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool Validate(List<RemapModel> remaps)
|
private static bool Validate(List<RemapModel> remaps)
|
||||||
{
|
{
|
||||||
var duplicateGroups = remaps
|
var duplicateGroups = remaps
|
||||||
.GroupBy(m => m.NewTypeName)
|
.GroupBy(m => m.NewTypeName)
|
||||||
.Where(g => g.Count() > 1)
|
.Where(g => g.Count() > 1)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (duplicateGroups.Count > 1)
|
if (duplicateGroups.Count <= 1) return true;
|
||||||
{
|
|
||||||
Logger.Log($"There were {duplicateGroups.Count()} duplicated sets of remaps.", ConsoleColor.Yellow);
|
Logger.Log($"There were {duplicateGroups.Count} duplicated sets of remaps.", ConsoleColor.Yellow);
|
||||||
|
|
||||||
foreach (var duplicate in duplicateGroups)
|
foreach (var duplicate in duplicateGroups)
|
||||||
{
|
{
|
||||||
@ -172,17 +168,15 @@ public class ReMapper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// First we filter our type collection based on simple search parameters (true/false/null)
|
/// First we filter our type collection based on simple search parameters (true/false/null)
|
||||||
/// where null is a third disabled state. Then we score the types based on the search parameters
|
/// where null is a third disabled state. Then we score the types based on the search parameters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mapping">Mapping to score</param>
|
/// <param name="mapping">Mapping to score</param>
|
||||||
|
/// <param name="types">Types to filter</param>
|
||||||
private void ScoreMapping(RemapModel mapping, IEnumerable<TypeDef> types)
|
private void ScoreMapping(RemapModel mapping, IEnumerable<TypeDef> types)
|
||||||
{
|
{
|
||||||
var tokens = DataProvider.Settings?.TypeNamesToMatch;
|
var tokens = DataProvider.Settings.TypeNamesToMatch;
|
||||||
|
|
||||||
if (mapping.UseForceRename)
|
if (mapping.UseForceRename)
|
||||||
{
|
{
|
||||||
@ -192,7 +186,7 @@ public class ReMapper
|
|||||||
|
|
||||||
// Filter down nested objects
|
// Filter down nested objects
|
||||||
types = !mapping.SearchParams.NestedTypes.IsNested
|
types = !mapping.SearchParams.NestedTypes.IsNested
|
||||||
? types.Where(type => tokens!.Any(token => type.Name.StartsWith(token)))
|
? types.Where(type => tokens.Any(token => type.Name.StartsWith(token)))
|
||||||
: types.Where(t => t.DeclaringType != null);
|
: types.Where(t => t.DeclaringType != null);
|
||||||
|
|
||||||
if (mapping.SearchParams.NestedTypes.NestedTypeParentName != string.Empty)
|
if (mapping.SearchParams.NestedTypes.NestedTypeParentName != string.Empty)
|
||||||
@ -249,23 +243,23 @@ public class ReMapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
var typeTable = (Dictionary<string, Type>)templateMappingClass
|
var typeTable = (Dictionary<string, Type>)templateMappingClass
|
||||||
.GetField("TypeTable")
|
.GetField("TypeTable")!
|
||||||
.GetValue(templateMappingClass);
|
.GetValue(templateMappingClass)!;
|
||||||
|
|
||||||
BuildAssociationFromTable(typeTable!, "ItemClass");
|
BuildAssociationFromTable(typeTable, "ItemClass");
|
||||||
|
|
||||||
var templateTypeTable = (Dictionary<string, Type>)templateMappingClass
|
var templateTypeTable = (Dictionary<string, Type>)templateMappingClass
|
||||||
.GetField("TemplateTypeTable")
|
.GetField("TemplateTypeTable")!
|
||||||
.GetValue(templateMappingClass);
|
.GetValue(templateMappingClass)!;
|
||||||
|
|
||||||
BuildAssociationFromTable(templateTypeTable!, "TemplateClass");
|
BuildAssociationFromTable(templateTypeTable, "TemplateClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildAssociationFromTable(Dictionary<string, Type> table, string extName)
|
private void BuildAssociationFromTable(Dictionary<string, Type> table, string extName)
|
||||||
{
|
{
|
||||||
foreach (var type in table)
|
foreach (var type in table)
|
||||||
{
|
{
|
||||||
if (!DataProvider.ItemTemplates!.TryGetValue(type.Key, out var template) ||
|
if (!DataProvider.ItemTemplates.TryGetValue(type.Key, out var template) ||
|
||||||
!type.Value.Name.StartsWith("GClass"))
|
!type.Value.Name.StartsWith("GClass"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -331,7 +325,7 @@ public class ReMapper
|
|||||||
{
|
{
|
||||||
var moduleName = Module?.Name;
|
var moduleName = Module?.Name;
|
||||||
|
|
||||||
var dllName = "-cleaned-remapped-publicized.dll";
|
const string dllName = "-cleaned-remapped-publicized.dll";
|
||||||
OutPath = Path.Combine(OutPath, moduleName?.Replace(".dll", dllName));
|
OutPath = Path.Combine(OutPath, moduleName?.Replace(".dll", dllName));
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -359,9 +353,9 @@ public class ReMapper
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DataProvider.Settings?.MappingPath != string.Empty)
|
if (DataProvider.Settings.MappingPath != string.Empty)
|
||||||
{
|
{
|
||||||
DataProvider.UpdateMapping(DataProvider.Settings!.MappingPath!.Replace("mappings.", "mappings-new."), _remaps);
|
DataProvider.UpdateMapping(DataProvider.Settings.MappingPath.Replace("mappings.", "mappings-new."), _remaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
new Statistics(_remaps, Stopwatch, OutPath, hollowedPath)
|
new Statistics(_remaps, Stopwatch, OutPath, hollowedPath)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user